Breaking up a file into blocks
Hi,
Would like to ask if anyone knows how to split up a file into blocks of a certain size. I'm programming in C. Any help would be very much appreciated. Thanks. |
You want to write something to do this? How about reading the file into an array of desired size, stop reading, write array out to file.001, read next portion, write out to file.002, etc...
|
FWIW -
dd will do that, and you don't have to write code to do it. split will also whack files into smaller pieces. |
Thanks for your replies... Actually, what I'm trying to do is to write a program where cryptography is involved. As such, I would like to be able to split the file up into blocks within the program itself. I'll give the array method a try...
Thanks again... :) |
If you are going to make it a GPL'd program, then use the sources for the GNU tool "split" (part of the GNU coreutils package)
|
yeah could you give me an example on how "dd" would do it...
lets say i got file 20MB and i want 5MB chunks... |
if you have split, you can do this:
Code:
split -b 5242880 /path/to/file1 /path/to/chunks/outputprefix Code:
split -b 5242880 /home/user/CoolMovie.mpg /tmp/split/movie |
With dd:
dd if=your-input-file of=first-out-file skip=0 count=10240 dd if=your-input-file of=second-out-file skip=10240 count=10240 dd if=your-input-file of=third-out-file skip=20480 count=10240 dd if=your-input-file of=fourth-out-file skip=30720 count=10240 etc... Assuming block size is 512 bytes. |
Quote:
using the 20MB example... hehe... i get it... 5242880 is 5MB right? so the size of the chunk should be specified in bytes? |
Right! :)
|
All times are GMT -5. The time now is 11:10 AM. |