in reply to Splitting a binary file

I tore out some other stuff and added a (little) error checking to these I wrote a while back. Much more could be done to them, but they served my purpose and may be of use to you.

splitf.pl

#! perl -slw use strict; use Digest::MD5 qw[md5_hex]; my( $file, $size, $path ) = @ARGV; die "$0 file size [path]" unless @ARGV >= 2 and ( -e $file or print "$file does not exists" ) and ( not -z $file or print "$file is zero size" ) and ( $size or print "You must specify a non-zero part size" ) and ( $size <= -s $file or print "The part size must be < filesize +" ); $path = '' unless $path; open my $index, '>', "$path/$file.idx" or die "path/$file.idx: $!"; local $/ = \$size; open my $data, '< :raw', $file or die "$file : $!"; my $n = '00000'; my $fullmd5 = new Digest::MD5; while( <$data> ) { $fullmd5->add( $_ ); my $partmd5 = md5_hex( $_ ); open my $part, '>:raw', "$path/$file.$n" or die $!; printf $part $_; close $part; print $index "$file.$n : $partmd5"; $n++; } close $data; print $index "$file : ", $fullmd5->hexdigest; close $index;
>

joinf.pl

#! perl -slw use strict; use Digest::MD5 qw[md5_hex]; die "$0 file.idx" unless @ARGV and -e $ARGV[ 0 ]; my( $index, $path ) = @ARGV; $path = '' unless $path; open my $idxfh, '<', $index or die "$index : $!"; chomp( my @files = <$idxfh> ); close $idxfh; my( $outfile, $md5 ) = split ' : ', pop @files; open my $out, '>:raw', "$path/$outfile" or die "$path/$outfile : $!"; my $fullmd5 = new Digest::MD5; local $/; for my $part ( @files ) { my( $partfile, $partmd5_1 ) = split ' : ', $part; open my $partfh, '<:raw', $partfile or die $!; my $in = <$partfh>; close $partfh; my $partmd5_2 = md5_hex $in; warn "Mismatch md5 $part -v- $partmd5_2\n" unless $partmd5_1 eq $partmd5_2; $fullmd5->add( $in ); printf $out $in; } close $out; print "File: $outfile reconstructed. The md5s ", ( $md5 eq $fullmd5->hexdigest ) ? 'match' : 'do not match';

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco.
Rule 1 has a caveat! -- Who broke the cabal?