Splitting Files for Floppy Disks

I wrote this script about a year ago, in August 1994, to solve a simple problem: moving large files when all you have are floppy disks and unreliable modem connections.

The situation comes up more than you would think. You have a file that is larger than a floppy disk. Maybe it is a software distribution, maybe a database dump. You need to get it from one machine to another, but the only reliable transport you have is a box of 1.44 MB floppies. Or you are transferring over a modem connection that drops after a certain file size and you need to break the transfer into smaller pieces.

Unix has a split command, but it works on line boundaries, which is not what you want for binary files. I wanted something that would split any file, binary or text, into pieces that fit on a floppy disk. And I wanted it to work everywhere I had Perl installed, which at this point means DOS, Unix, and Mac.

So I wrote split.pl. It reads a file byte by byte and writes out numbered pieces, each no larger than 1,400,000 bytes (a safe size for a 1.44 MB floppy with some room for the filesystem overhead).

Here is the complete source:

#!/usr/local/bin/perl
# Program name: split.pl
# Author: Rajiv Pant (Betul)   [email protected]   http://rajiv.org
# Version 1.0. August, 1994

# Note: Documentation is at end.

$BigFile = shift ;

$DiskSize = 1_400_000 ;

open (BIGFILE, $BigFile) ;

while (read (BIGFILE, $c, 1))
  {
  $SmallFileNumber = int (1 + $byte/$DiskSize) ;
  if ($SmallFileNumber != $PreviousSmallFileNumber)
    {
    print "Creating new file: $BigFile.$SmallFileNumber\n" ;
    open (SMALLFILE, ">$BigFile.$SmallFileNumber") ;
    }
  print SMALLFILE $c ;
  $byte++ ;
  $PreviousSmallFileNumber = $SmallFileNumber ;
  }

close (SMALLFILE) ;
close (BIGFILE) ;

To use it, just run perl split.pl bigfile.tar.gz and it creates bigfile.tar.gz.1, bigfile.tar.gz.2, and so on. Each piece fits on a floppy.

To combine the pieces back together, you do not need any special software. On Unix: cat bigfile.tar.gz.* > bigfile.tar.gz. On DOS: copy /b bigfile.tar.gz.1 + bigfile.tar.gz.2 bigfile.tar.gz. That is it.

The script is intentionally simple. It reads one byte at a time, which is not the fastest approach, but it is completely portable and correct for any file type. No assumptions about line endings or character encoding. Binary files, text files, compressed archives, it does not matter.

I have used this on SunOS, Linux, DOS with a Perl port, and System 7. Perl is the same language everywhere, so the script just works. That is the nice thing about writing utilities in Perl: you write it once and carry it with you.