On 20 Sep 2012, at 17:33, Antonio Roberts antonio@hellocatfood.com wrote:
I'm attempting to use [binfile] to add additional bytes to a file. If I first read the file - using [read( - and then specify the write position - [writeat 0 ( - when I add bytes they _overwrite_ the already existing bytes instead of adding new ones.
Previously I have used one [binfile] object to read a file output each byte of it to another [binfile] object. This method has worked great for small files but when I'm faced with 60mb files it takes far too long!
Is there a way to add bytes to the beginning of a file without overwriting?
DId you solve this in the end?
[binfile] could be trivially extended to allow an |insert( method, which inserts bytes without overwriting. However, I suspect this kind of insert operation is going to be relatively inefficient even if it's done on the C side.
Another option, as I suggested off-list is to use [shell] + "cat", but this isn't portable.
Something else you could explore is using [pdlua] and a bit of Lua script: http://www.lua.org/pil/21.2.2.html
For the sort of work you're doing it wouldn't hurt to incorporate pdlua into your toolbox anyhow.
best,
Jamie