Re: Is BlobBuilder needed?

On Mon, Oct 24, 2011 at 4:46 PM, Tab Atkins Jr. <jackalmage@gmail.com> wrote:
> On Mon, Oct 24, 2011 at 4:33 PM, Eric U <ericu@google.com> wrote:
>> The only things that this lacks that BlobBuilder has are the endings
>> parameter for '\n' conversion in text and the content type.  The
>> varargs constructor makes it awkward to pass in flags of any
>> sort...any thoughts on how to do that cleanly?
>
> Easy.  The destructuring stuff proposed for ES lets you easily say things like:
>
> function(blobparts..., keywordargs) {
>  // blobparts is an array of all but the last arg
>  // keywordargs is the last arg
> }
>
> or even:
>
> function(blobparts..., {contenttype, lineendings}) {
>  // blobparts is an array of all but the last arg
>  // contenttype and lineendings are pulled from the
>  // last arg, if it's an object with those properties
> }

The problem is that if the caller has an array, because this is a
constructor, this will get *very* awkward to do until ES6 is actually
implemented.

You can't simply do:

new Blob.apply(blobarray.concat("text/plain"));

I *think* this is what you'd have to do in a ES5 compliant engine:

new Blob.bind([null].concat(blobarray, "text/plain));

In ES3 I don't even think that there's a way to do it. Though that
might not matter assuming everyone gets .bind correctly implemented
before they implement |new Blob|.

I don't think the complexity is worth it for a dubious gain. I.e. it's
not entirely clear to me that the following:

new Blob(blob1, blob2, mybuffer, blob3, "somestring", "text/plain");

is significantly better than

new Blob([blob1, blob2, mybuffer, blob3, "somestring"], "text/plain");

/ Jonas

Received on Tuesday, 25 October 2011 01:41:03 UTC