[PD] Looking for a way to add bytes to beginning of a file using [binfile]

Antonio Roberts antonio at hellocatfood.com
Sun Sep 23 19:02:09 CEST 2012


If anyone is interested I wrote a tutorial on using [binfile] to
create jpg images using only Pure Data
http://www.hellocatfood.com/2012/09/23/create-jpgs-in-pure-data/

On 22 September 2012 18:02, Antonio Roberts <antonio at hellocatfood.com> wrote:
> After some experimenting I solved the problem.
>
> I first add the bytes that I want to add. I then use a second
> [binfile] object and use a loop ( [bang( / [until] ) to send each byte
> to the other [binfile]. This adds bytes instead of overwriting.
>
> On 22 September 2012 11:41, Jamie Bullock <jamie at postlude.co.uk> wrote:
>>
>> On 20 Sep 2012, at 17:33, Antonio Roberts <antonio at 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
>>
>>
>>
>
>
>
> --
> ============================
> antonio at hellocatfood.com
> http://www.hellocatfood.com
> ============================



-- 
============================
antonio at hellocatfood.com
http://www.hellocatfood.com
============================



More information about the Pd-list mailing list