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?

In reply to Re: Splitting a binary file by BrowserUk
in thread Splitting a binary file by warthurton

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.