Whoa, this happened suddenly. If this goes out, it may be the Gears
API that has undergone the least design scrutiny!
A couple thoughts:
(1) How much does this help YouTube? I think realistically, any new
API won't get out to end users for some time (October at the
earliest). Do they need a workaround sooner?
(2) I'm not sure about the model. I feel like Blobs have been moving
toward parallelism with Strings / Arrays, and that seems like a good
path to continue down.
For example, most methods that today take a String could instead
accept a StringOrBlob. Both objects represent a chunk of immutable
data; it just happens to be text- or binary-based data.
Instead of 'StringBuilder' or 'ArrayBuilder' classes, there are
methods like concat(). Couldn't we add Blob.concat(), and let it
accept a String or Blob?
A nice advantage of that approach is that it's more likely to be
accepted by standards bodies, I think. (In the standards discussions,
the Blob is sometimes thought of as "immutable ByteArray".)
--Chris
On Wed, Sep 10, 2008 at 5:55 PM, Nigel Tao <[EMAIL PROTECTED]> wrote:
>
> This is mostly just an announcement (since I forgot to send out the
> initial mail requesting a code review).
>
> I have just submitted 8226669, which introduces a new
> JavaScript-visible BlobBuilder module, where one can concatenate
> strings and blobs together to make one big blob. A particular use case
> is allowing a GearsHttpRequest to upload multiple files in the same
> multipart format that an HTML form does. Example code looks like this:
>
> var file = ...; // As received from desktop.openFiles().
> var boundary = '------multipartformboundary' + someRandomAlphaNumerics;
> var dashDash = '--';
> var crlf = '\r\n';
> var dashDashBoundaryCrlf = dashDash + boundary + crlf;
>
> var blobBuilder = google.gears.factory.create('beta.blobbuilder');
> builder.append(dashDashBoundaryCrlf);
> builder.append('Content-Disposition: form-data; name="' + name + '"');
> if (file.name) {
> builder.append('; filename="' + file.name + '"');
> }
> builder.append(crlf);
> builder.append('Content-Type: application/octet-stream');
> builder.append(crlf);
> builder.append(crlf);
> builder.append(file.blob);
> builder.append(crlf);
> builder.append(dashDash);
> builder.append(boundary);
> builder.append(dashDash);
> builder.append(crlf);
>
> var request = google.gears.factory.create('beta.httprequest');
> request.open('POST', '...');
> request.setRequestHeader('content-type', 'multipart/form-data;
> boundary=' + boundary);
> request.send(blobBuilder.getAsBlob());
>