W3C home > Mailing lists > Public > public-webapps@w3.org > October to December 2010

Re: using BlobBuilder append method with generated binary data

From: Toni Ruottu <toni.ruottu@iki.fi>
Date: Tue, 16 Nov 2010 17:25:15 +0200
Message-ID: <AANLkTikEdGaxJXqAuBBpAeWnDiNz6nh6P0vhMM8BU62Y@mail.gmail.com>
To: Eric Uhrhane <ericu@google.com>
Cc: public-webapps@w3.org
Sorry for slow answer. Took me a while to get on top of this. I think
they just might answer my problem. However, I can not really tell
before I see a working implementation. I wrote a test. See
http://www.cs.helsinki.fi/u/twruottu/testi/bpost3.html It does not
currently work with the latest development version of Chrome. I
wonder, if I am doing something wrong.

  --Toni

On Wed, Oct 20, 2010 at 6:17 PM, Eric Uhrhane <ericu@google.com> wrote:
> Toni:
>
>    BlobBuilder now has an append() method that takes an ArrayBuffer,
> and FileReader has readAsArrayBuffer.  Do these together satisfy your
> needs?
>
>        Eric
>
> On Wed, Oct 20, 2010 at 3:39 AM, Toni Ruottu <toni.ruottu@iki.fi> wrote:
>> I have discussed the topic before on some Chromium bug threads. I
>> searched the archives of this mailing list for blobs and generated
>> content, but was not too successful. There may be multiple different
>> reasons why one would need to build blobs from generated data. The one
>> that concerns me, is being able to do binary POSTs with XmlHTTPRequest
>> in a standard manner. To send binary data over XHR one is required to
>> send out a blob, but first the blob needs to be constructed with
>> BlobBuilder. Let me fill you in on how I see the current situation.
>> Maybe someone can spot an error in my line of thought.
>>
>> A new (empty) BlobBuilder is created by stating...
>> var bb = new BlobBuilder();
>>
>> After creating a BlobBuilder, the user appends some data into the blob
>> being generated by using the append function. The append function is
>> overloaded and can be used to append multiple different types of data
>> into the blob. Currently only existing blobs, and utf-8 text are
>> supported.
>>
>> One can add an existing blob into the new one by doing...
>> bb.append(existingBlob);
>>
>> One can add a text string in utf-8 format by doing...
>> bb.append(aTextString);
>>
>> Once the data is in there, it is possible to construct the new blob with...
>> var blob = bb.getBlob()
>>
>> A blob has a slice method which makes it possible to turn a large blob
>> into smaller ones. It is thus possible to cut out single bytes from a
>> blob and use them construct new blobs by appending copies of these
>> sample bytes together with the BlobBuilder.
>>
>> As sample bytes can only be generated by writing text into the blob as
>> utf-8, it is not possible to generate all 8-bit patterns. More
>> specifically, the bit patterns that are illegal in any given utf-8
>> string, are not possible to generate using the current API. This leads
>> developers into using various hacks to overcome the issue.
>>
>> For example one could ask the user to provide a file with sample
>> bytes. Methods for reading a file into a blob are available, so there
>> is no need to generate the sample bytes. There is however no way to
>> make sure that the user provided a file with correct bit-patterns as
>> the blob interface is to a large degree a read-only interface. A
>> demonstration of using a file to overcome the issue is available at
>> http://www.cs.helsinki.fi/u/twruottu/testi/bpost.html
>>
>> To solve the problem a third append function which accepts a list of
>> integers, and adds the corresponding bytes into the blob is needed.
>> Once such method has been introduced it should be possible to write
>> the 7-bit ascii string "foo" into a BlobBuilder by doing...
>> bb.append([102,111,111]);
>>
>> It should also be possible to add bytes 0x00 and 0xff into the
>> BlobBuilder by doing...
>> bb.append([0,255]);
>>
>> Would such append method be a possible addition as I defined it? Is
>> there some alternative way for achieving the same result. Which
>> specification should such feature go into?
>>
>>
>>  thank you for your time, --Toni Ruottu
>>
>>
>>
>
Received on Tuesday, 16 November 2010 15:25:48 GMT

This archive was generated by hypermail 2.3.1 : Tuesday, 26 March 2013 18:49:42 GMT