using BlobBuilder append method with generated binary data

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 Wednesday, 20 October 2010 14:10:19 UTC