There are many reasons to want to split file into chunks - mainly for network transfer (e.g. e-mail attachments) but I'm sure there are scenarios that could require such thing I cannot imagine. So how can a file be split into chunks that can be easily assembled back to original file (including non-windows systems) ?
What are possibilities:
- MAKECAB - the built-in Windows archiver - it can compress file and split it , but will be difficult to assemble the file on non-Windows machine.
- WSH/Jscript/VBscript - binary files can be easy processed with ADODB Streams.And according to me JScript is preferable.
- .NET/JScript.net/VB/C# - As .NET comes with command line compilers it also can be used for this purpose . .NET binary streams probably are the best in this case that it can offer .
- CERTUTIL - as it can convert a binary file to HEX and back it's possible to process the HEX data with batch file and split the file to chunks.
Probably GZipStreams can be used also as they allows reading bytes (and offer portable compression !).I promise an upvote If anyone succeed with this (or offer any other method) :-)
The example below will split a file, producing multiple output files all smaller than the
maxChunkSize
supplied. To reassemble, you can usecopy /b
.SplitFile.cs
(compile with
c:\Windows\Microsoft.NET\Framework\v2.0.50727\csc /out:splitFile.exe SplitFile.cs
)Example Use:
Some time ago I wrote a Batch-JScript hybrid script called BinToBat.bat with this purpose. This is its help screen:
You may download BinToBat.bat program from this site.
With all scripts syntax is the same - the file to split and the size in bytes.
1) MAKECAB - the main limitation is the usage on Unix/Mac machines.For unix eventually cabextract or 7zip could be used , but I'm not sure if it can handle split CAB file .Even on windows the EXPAND command cant do it and EXTRAC32 (command is given in the help message) should be used (or Shell.Application )
--All other methods are direct splitting and files can be assembled with appending them to each other in correct order --
2) JScript - a hybrid file that must be saved with .bat extension
3) JScript.net - self compiled hybrid that must be saved with .bat extension.
4) CERTUTIL - rather an experimental stuff - it's slower as the buffers are limited to the max length that can string have 8,1** characters and is rather text processing:
here's a script that can assemble files split with the last three methods: