What is a good way to join files together?

Everything else that doesn't fall into one of the other PB categories.
rich
New User
New User
Posts: 6
Joined: Thu Oct 30, 2003 8:20 pm
Location: UK
Contact:

What is a good way to join files together?

Post by rich »

Hi all,

I have written a program which successfully downloads a file from a web site. The file is downloaded in 1MB chunks. The end result being that I have approx. 200 "chunks" in my temporary folder and I need a bullet-proof way to stitch them back together again into a single file.

Does anyone have any suggestions as how best to achieve this? I thought I could use OpenFile to create my new file and then read in each chunk one after the other and write the data out with WriteData, but I am worried that the file buffer will never actually save until I call CloseFile (or the app ends?) and i'll fill up my memory with 200MB+ worth of file buffer data.

Any ideas very welcome.

Thanks,

Rich
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

file system is not stored in memory when using the purebasic commands (except for windows caching)
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
rich
New User
New User
Posts: 6
Joined: Thu Oct 30, 2003 8:20 pm
Location: UK
Contact:

Post by rich »

For anyone else who reads this - I found a rather elegant and fast solution to this other than the byte by byte reading process. I basically create a batch file that just has a single copy command in it, such as:

copy /y part1.bin /b + part2.bin /b + part3.bin /b DestFile.zip /b

(The /y surpresses output, the /b means join as binary)

I then just run the batch file with RunProgram, set to halt until it's finished and show no output.

Works a treat! I managed to join together an entire CD ISO image this way (720 x 1MB chunks) with no errors. I was impressed that the copy command could handle having 720 "parameters" passed to it :)

It may not be cross-platform, but that's not an issue in this case. And it was certainly quicker than a byte for byte copy.

Rich
Post Reply