views:

482

answers:

2

In my application, the user selects a big file (>100 mb) on their drive. I wish for the program to then take the file that was selected and chop it up into archived parts that are 100 mb or less. How can this be done? What libraries and file format should I use? Could you give me some sample code? After the first 100mb archived part is created, I am going to upload it to a server, then I will upload the next 100mb part, and so on until the upload is finished. After that, from another computer, I will download all these archived parts, and then I wish to connect them into the original file. Is this possible with the 7zip libraries, for example? Thanks!

UPDATE: From the first answer, I think I'm going to use SevenZipSharp, and I believe I understand now how to split a file into 100mb archived parts, but I still have two questions:

  1. Is it possible to create the first 100mb archived part and upload it before creating the next 100mb part?
  2. How do you extract a file with SevenZipSharp from multiple splitted archives?

UPDATE #2: I was just playing around with the 7-zip GUI and creating multi-volume/split archives, and I found that selecting the first one and extracting from it will extract the whole file from all of the split archives. This leads me to believe that paths to the subsequent parts are included in the first one (or is it consecutive?). However, I'm not sure if this would work directly from the console, but I will try that now, and see if it solves question #2 from the first update.

+1  A: 

Take a look at SevenZipSharp, you can use this to create your spit 7z files, do whatever you want to upload them, then extract them on the server side.

To split the archive look at the SevenZipCompressor.CustomParameters member, passing in "v100m". (you can find more parameters in the 7-zip.chm file from 7zip)

Philip Rieck
And as for re-connecting the split archives once they are downloaded on the other computer?
Maxim Zaslavsky
Also, is it possible to make the first 100mb part, then upload it before making the second part, then create the next one, upload it, etc.?
Maxim Zaslavsky
@Maxim Z - to re-connect you just use the 7zip lib to decompress the first one. you can *not* make the first part and upload it before making the next, as 7zip can modify any/all parts when it splits them until the full compression is done. You can try using SharpZipLib and .zip compression if that is an issue.
Philip Rieck
A: 

You can split the data into 100MB "packets" first, and then pass each packet into the compressor in turn, pretending that they are just separate files.

However, this sort of compression is usually stream-based. As long as the library you are using will do its I/O via a Stream-derived class, it would be pretty simple to implement your own Stream that "packetises" the data any way you like on the fly - as data is passed into your Write() method you write it to a file. When you exceed 100MB in that file, you simply close that file and open a new one, and continue writing.

Either of these approaches would allow you to easily upload one "packet" while continuing to compress the next.

edit

Just to be clear - Decompression is just the reverse sequence of the above, so once you've got the compression code working, decompression will be easy.

Jason Williams