File writing (stumped!?)

Blitz3D Forums/Blitz3D Beginners Area/File writing (stumped!?)

Aha! I had this working before as you've posted it above, but for some reason it kept on infinitely writing (as your code does, I kept stopping it at around 50 megs) and it was never reaching EOF. I couldn't figure out why, and my other method (the first one) didn't write at all. However, something in the way you just explained it made me realise why..

Of course, unless the file is evenly divisible by 4 (the length of the INT), then once it writes the last INT, its no longer at the EOF, so it writes another one, etc etc ad nauseum. :) To fix it, I wrote another EOF check which EXITs the loop if the following byte is past the end of the file.

Thanks immensely for your help. :)

timer=MilliSecs()
	
fileout=OpenFile("test.txt")
Print "opened!"

Repeat
SeekFile fileout,FilePos(fileout)
WriteInt fileout,-1843115630
SeekFile fileout,FilePos(fileout)+1
If Eof(fileout) Then Exit
SeekFile fileout,FilePos(fileout)-2
Forever
CloseFile fileout
	
timeelapsed=MilliSecs()-timer
Print timeelapsed/1000
Print "done!  "
Delay 200
End
Oh, the -2 is for my own use. I'm writing INTs (for speed) but actually only want to write 3 bytes, not 4, for the bit-masking pattern. This is a crap way of doing it, so now that I've got the seeking sorted out, I'll get it to dynamically create memory banks up to 5 megs, containing the bitmask to write, to drastically speed up large-file shredding. At the moment, with the code above, it takes about 10 seconds per meg. But considering I'm writing 35 passes (27+8 random data), 4.5 minutes per meg is a little on the slow side. ;) Writing 5 meg chunks should reduce this to about 2 seconds per meg. :)

+BlackD