Re: BlobBuilder.append() should take ArrayBufferView in addition to ArrayBuffer

2012-04-29 Thread Glenn Maynard
On Sun, Apr 29, 2012 at 2:41 PM, Jonas Sicking  wrote:

> I don't know what you are using as basis for the "it's probably by far
> the most common actual data type" statement.
>

Every multibyte string is an array of bytes.  Compressed data is an arrays
of bytes (or rather bitstreams, which are accessed as bytes).  Files and
network requests which are entirely arrays of 16- or 32-bit units are
pretty uncommon.

The whole point of the ArrayBuffer/ArrayBufferView split is that
> ArrayBuffers represent data of which you don't know the type, whereas
> ArrayBufferView is for when you know the type.
>

No, that's not the point.  DataView is an ArrayBufferView, and DataView
isn't typed.  The whole point of the ArrayBuffer/ArrayBufferView split is
that ArrayBuffer represents storage, where ArrayBufferView represents a
lightweight slice of that storage.  It's perfectly fine to create an
Int8Array from a slice of an ArrayBuffer, even if the data is really 32-bit
floats, when you don't care about the contents and just want to create a
slice.  (You can do that with DataView, too, but there's nothing wrong with
using Int8Array for this.)

You might not like that design (I don't), but it's what we have.
> Hopefully ES6 will grow something better at which time we can support
> that.
>

Having two APIs for the same thing, even if it's better designed, seems
likely to cost more than the gain.  If we *really* think that this is going
to happen, it might be a bad idea to add ArrayBuffer to more and more
APIs...

-- 
Glenn Maynard


Re: BlobBuilder.append() should take ArrayBufferView in addition to ArrayBuffer

2012-04-29 Thread Jonas Sicking
On Sat, Apr 28, 2012 at 7:54 AM, Glenn Maynard  wrote:
> On Sat, Apr 28, 2012 at 3:45 AM, Jonas Sicking  wrote:
>>
>> We should not have readAsArryBufferView since there's a ton of
>> different types of ArrayBufferViews. Instead we should just return an
>> ArrayBuffer and let people construct ArrayBufferViews or DataViews
>> into that as they see fit.
>
>
> It would have made sense to return an Int8Array in all cases instead of an
> ArrayBuffer: it's probably by far the most common actual data type, treating
> buffers as char* by default isn't unusual, and it allows passing the results
> of one API directly into another API.  Having API inputs and outputs use two
> different types is pretty asymmetric.
>
> (I say that in past tense; it's probably too late to fix this.  Also, I'd
> rather live with that asymmetry than have every single ArrayBuffer entry
> point have separate ArrayBuffer and ArrayBufferView overloads.)

I don't know what you are using as basis for the "it's probably by far
the most common actual data type" statement.

The whole point of the ArrayBuffer/ArrayBufferView split is that
ArrayBuffers represent data of which you don't know the type, whereas
ArrayBufferView is for when you know the type.

You might not like that design (I don't), but it's what we have.
Hopefully ES6 will grow something better at which time we can support
that.

/ Jonas



Re: BlobBuilder.append() should take ArrayBufferView in addition to ArrayBuffer

2012-04-28 Thread Glenn Maynard
On Sat, Apr 28, 2012 at 3:45 AM, Jonas Sicking  wrote:

> We should not have readAsArryBufferView since there's a ton of
> different types of ArrayBufferViews. Instead we should just return an
> ArrayBuffer and let people construct ArrayBufferViews or DataViews
> into that as they see fit.
>

It would have made sense to return an Int8Array in all cases instead of an
ArrayBuffer: it's probably by far the most common actual data type,
treating buffers as char* by default isn't unusual, and it allows passing
the results of one API directly into another API.  Having API inputs and
outputs use two different types is pretty asymmetric.

(I say that in past tense; it's probably too late to fix this.  Also, I'd
rather live with that asymmetry than have every single ArrayBuffer entry
point have separate ArrayBuffer and ArrayBufferView overloads.)

-- 
Glenn Maynard


Re: BlobBuilder.append() should take ArrayBufferView in addition to ArrayBuffer

2012-04-28 Thread Jonas Sicking
On Fri, Apr 27, 2012 at 10:57 AM, Arun Ranganathan
 wrote:
>
> On Apr 27, 2012, at 1:28 AM, Anne van Kesteren wrote:
>
>> On Fri, 27 Apr 2012 00:13:42 +0200, Arun Ranganathan 
>>  wrote:
>>> The constructor will switch to use ArrayBufferView in lieu of ArrayBuffer, 
>>> but the read method exposed on FileReader and FileReaderSync will read 
>>> files into memory as ArrayBuffers.
>>
>> Since the constructor is not widely deployed yet would it not be better to 
>> stick to ArrayBufferView exclusively, just like XMLHttpRequest.send()?
>
>
> The Blob constructor will already use ArrayBufferView.  Above, do you mean, 
> have a method of the sort FileReader.readAsArrayBufferView or something like 
> that?
>
> *.readAsArrayBuffer is already deployed, and it might be weird to force a 
> view on an ArrayBuffer when read into memory.

We should not have readAsArryBufferView since there's a ton of
different types of ArrayBufferViews. Instead we should just return an
ArrayBuffer and let people construct ArrayBufferViews or DataViews
into that as they see fit.

This matches what XHR does (and intends to do) I believe.

/ Jonas



Re: BlobBuilder.append() should take ArrayBufferView in addition to ArrayBuffer

2012-04-27 Thread Arun Ranganathan

On Apr 27, 2012, at 1:28 AM, Anne van Kesteren wrote:

> On Fri, 27 Apr 2012 00:13:42 +0200, Arun Ranganathan 
>  wrote:
>> The constructor will switch to use ArrayBufferView in lieu of ArrayBuffer, 
>> but the read method exposed on FileReader and FileReaderSync will read files 
>> into memory as ArrayBuffers.
> 
> Since the constructor is not widely deployed yet would it not be better to 
> stick to ArrayBufferView exclusively, just like XMLHttpRequest.send()?


The Blob constructor will already use ArrayBufferView.  Above, do you mean, 
have a method of the sort FileReader.readAsArrayBufferView or something like 
that?  

*.readAsArrayBuffer is already deployed, and it might be weird to force a view 
on an ArrayBuffer when read into memory.

-- A*


> 
> 
> -- 
> Anne van Kesteren
> http://annevankesteren.nl/
> 




Re: BlobBuilder.append() should take ArrayBufferView in addition to ArrayBuffer

2012-04-27 Thread Glenn Maynard
On Fri, Apr 27, 2012 at 12:28 AM, Anne van Kesteren wrote:

> On Fri, 27 Apr 2012 00:13:42 +0200, Arun Ranganathan <
> aranganat...@mozilla.com> wrote:
>
>> The constructor will switch to use ArrayBufferView in lieu of
>> ArrayBuffer, but the read method exposed on FileReader and FileReaderSync
>> will read files into memory as ArrayBuffers.
>>
>
> Since the constructor is not widely deployed yet would it not be better to
> stick to ArrayBufferView exclusively, just like XMLHttpRequest.send()?


I think he's saying that the ctor (inputting data) will use ArrayBufferView
only, but FileReader (*outputting* data) returns an ArrayBuffer, like XHR's
arraybuffer response entity body.

I wish typed arrays could be fixed so ArrayBuffer is itself an
ArrayBufferView, to fix this inconsistency, but I think there are one or
two places in the API where it would break compat...

-- 
Glenn Maynard


Re: BlobBuilder.append() should take ArrayBufferView in addition to ArrayBuffer

2012-04-26 Thread Anne van Kesteren
On Fri, 27 Apr 2012 00:13:42 +0200, Arun Ranganathan  
 wrote:
The constructor will switch to use ArrayBufferView in lieu of  
ArrayBuffer, but the read method exposed on FileReader and  
FileReaderSync will read files into memory as ArrayBuffers.


Since the constructor is not widely deployed yet would it not be better to  
stick to ArrayBufferView exclusively, just like XMLHttpRequest.send()?



--
Anne van Kesteren
http://annevankesteren.nl/



Re: BlobBuilder.append() should take ArrayBufferView in addition to ArrayBuffer

2012-04-26 Thread Arun Ranganathan

On Apr 24, 2012, at 7:00 PM, David Herman wrote:

> On Apr 24, 2012, at 3:53 PM, David Herman wrote:
> 
>> On Apr 12, 2012, at 2:48 PM, Arun Ranganathan wrote:
>> 
>>> I intend to add ArrayBufferView as a parameter to the Blob constructor .
>> 
>> Would it be possible also to allow passing an ArrayBuffer with an offset and 
>> length as an additional alternative? This would eliminate the need to create 
>> a view when you just want a slice of the buffer but don't particularly 
>> want/need to think of it as a Uint8/Uint32/whatever array.
> 
> Oh, I just saw in the bug that the idea is to *eliminate* the ArrayBuffer 
> argument option entirely. If that's the case then disregard my question.


The constructor will switch to use ArrayBufferView in lieu of ArrayBuffer, but 
the read method exposed on FileReader and FileReaderSync will read files into 
memory as ArrayBuffers.  

-- A*


Re: BlobBuilder.append() should take ArrayBufferView in addition to ArrayBuffer

2012-04-24 Thread David Herman
On Apr 24, 2012, at 3:53 PM, David Herman wrote:

> On Apr 12, 2012, at 2:48 PM, Arun Ranganathan wrote:
> 
>> I intend to add ArrayBufferView as a parameter to the Blob constructor .
> 
> Would it be possible also to allow passing an ArrayBuffer with an offset and 
> length as an additional alternative? This would eliminate the need to create 
> a view when you just want a slice of the buffer but don't particularly 
> want/need to think of it as a Uint8/Uint32/whatever array.

Oh, I just saw in the bug that the idea is to *eliminate* the ArrayBuffer 
argument option entirely. If that's the case then disregard my question.

Dave




Re: BlobBuilder.append() should take ArrayBufferView in addition to ArrayBuffer

2012-04-24 Thread David Herman
On Apr 12, 2012, at 2:48 PM, Arun Ranganathan wrote:

> I intend to add ArrayBufferView as a parameter to the Blob constructor .

Would it be possible also to allow passing an ArrayBuffer with an offset and 
length as an additional alternative? This would eliminate the need to create a 
view when you just want a slice of the buffer but don't particularly want/need 
to think of it as a Uint8/Uint32/whatever array.

Dave




Re: BlobBuilder.append() should take ArrayBufferView in addition to ArrayBuffer

2012-04-12 Thread Simon Pieters

On Thu, 12 Apr 2012 22:11:38 +0200, Eric U  wrote:

On Thu, Apr 12, 2012 at 12:54 PM, Anne van Kesteren   
wrote:
On Thu, 12 Apr 2012 21:48:12 +0200, Boris Zbarsky   
wrote:


Because it's still in the current editor's draft and it's still in the
Gecko code and I was just reviewing a patch to it and saw the API?  ;)



Eric, the plan is to remove that from File Writer, no?


Yes.  The next draft I publish will mark it deprecated, and it will
eventually go away.


Please just remove it from the spec directly. If implementors feel they  
want to keep it around for a while longer, that's up to them, but the spec  
should describe the end goal.


As for implementations, it's usually simpler to remove features earlier  
than to wait a while and hope it will be possible to remove it later. The  
longer a feature is exposed on the Web, the more content will end up  
relying on it.



 However, currently at least Gecko and WebKit
support BlobBuilder, and WebKit doesn't yet have the Blob constructor,
so it'll be a little while before it actually fades away.

That being said, we should be talking about making this addition to
Blob, not to BlobBuilder.


I thought we discussed long ago it should be removed in favor of a
constructable(sp?) Blob?



Could be.  Like I said, it's still in the editor's draft.



Blob with constructor is in http://dev.w3.org/2006/webapi/FileAPI/




Also, should it not accept just ArrayBufferView then as per
XMLHttpRequest?



Is there existing content depending on BlobBuilder and its  
ArrayBufferView

stuff?



I thought the idea was to not have BlobBuilder at all.



--
Anne van Kesteren
http://annevankesteren.nl/



--
Simon Pieters
Opera Software



Re: BlobBuilder.append() should take ArrayBufferView in addition to ArrayBuffer

2012-04-12 Thread Arun Ranganathan
> On Thu, Apr 12, 2012 at 12:54 PM, Anne van Kesteren
>  wrote:
> > Eric, the plan is to remove that from File Writer, no?
> 
> Yes.  The next draft I publish will mark it deprecated, and it will
> eventually go away.  However, currently at least Gecko and WebKit
> support BlobBuilder, and WebKit doesn't yet have the Blob
> constructor,
> so it'll be a little while before it actually fades away.
> 
> That being said, we should be talking about making this addition to
> Blob, not to BlobBuilder.

I intend to add ArrayBufferView as a parameter to the Blob constructor .

-- A*



Re: BlobBuilder.append() should take ArrayBufferView in addition to ArrayBuffer

2012-04-12 Thread Eric U
On Thu, Apr 12, 2012 at 12:54 PM, Anne van Kesteren  wrote:
> On Thu, 12 Apr 2012 21:48:12 +0200, Boris Zbarsky  wrote:
>>
>> Because it's still in the current editor's draft and it's still in the
>> Gecko code and I was just reviewing a patch to it and saw the API?  ;)
>
>
> Eric, the plan is to remove that from File Writer, no?

Yes.  The next draft I publish will mark it deprecated, and it will
eventually go away.  However, currently at least Gecko and WebKit
support BlobBuilder, and WebKit doesn't yet have the Blob constructor,
so it'll be a little while before it actually fades away.

That being said, we should be talking about making this addition to
Blob, not to BlobBuilder.

>>> I thought we discussed long ago it should be removed in favor of a
>>> constructable(sp?) Blob?
>>
>>
>> Could be.  Like I said, it's still in the editor's draft.
>
>
> Blob with constructor is in http://dev.w3.org/2006/webapi/FileAPI/
>
>
>
>>> Also, should it not accept just ArrayBufferView then as per
>>> XMLHttpRequest?
>>
>>
>> Is there existing content depending on BlobBuilder and its ArrayBufferView
>> stuff?
>
>
> I thought the idea was to not have BlobBuilder at all.
>
>
>
> --
> Anne van Kesteren
> http://annevankesteren.nl/



Re: BlobBuilder.append() should take ArrayBufferView in addition to ArrayBuffer

2012-04-12 Thread Anne van Kesteren

On Thu, 12 Apr 2012 21:58:00 +0200, Boris Zbarsky  wrote:

On 4/12/12 3:54 PM, Anne van Kesteren wrote:

I thought the idea was to not have BlobBuilder at all.


Dunno.  Is there content depending on it?


Maybe some browser specific demos or content, it's not implemented by  
everyone:


  http://caniuse.com/#search=blobbuilder

We have specifically refrained from implementing it based on outcome of  
past discussions. If plans have suddenly changed that would be good to  
know.



--
Anne van Kesteren
http://annevankesteren.nl/



Re: BlobBuilder.append() should take ArrayBufferView in addition to ArrayBuffer

2012-04-12 Thread Boris Zbarsky

On 4/12/12 3:54 PM, Anne van Kesteren wrote:

Blob with constructor is in http://dev.w3.org/2006/webapi/FileAPI/


Right.  I'd ended up at the File Writer spec.


I thought the idea was to not have BlobBuilder at all.


Dunno.  Is there content depending on it?

-Boris



Re: BlobBuilder.append() should take ArrayBufferView in addition to ArrayBuffer

2012-04-12 Thread Anne van Kesteren

On Thu, 12 Apr 2012 21:48:12 +0200, Boris Zbarsky  wrote:
Because it's still in the current editor's draft and it's still in the  
Gecko code and I was just reviewing a patch to it and saw the API?  ;)


Eric, the plan is to remove that from File Writer, no?


I thought we discussed long ago it should be removed in favor of a  
constructable(sp?) Blob?


Could be.  Like I said, it's still in the editor's draft.


Blob with constructor is in http://dev.w3.org/2006/webapi/FileAPI/


Also, should it not accept just ArrayBufferView then as per  
XMLHttpRequest?


Is there existing content depending on BlobBuilder and its  
ArrayBufferView stuff?


I thought the idea was to not have BlobBuilder at all.


--
Anne van Kesteren
http://annevankesteren.nl/



Re: BlobBuilder.append() should take ArrayBufferView in addition to ArrayBuffer

2012-04-12 Thread Boris Zbarsky

On 4/12/12 3:44 PM, Anne van Kesteren wrote:

On Thu, 12 Apr 2012 21:26:24 +0200, Boris Zbarsky  wrote:

This should make it easier to append limited views; appending the
.buffer is a footgun because it appends the whole buffer.


Why are we still discussing BlobBuilder?


Because it's still in the current editor's draft and it's still in the 
Gecko code and I was just reviewing a patch to it and saw the API?  ;)



I thought we discussed long ago it should be removed in favor of a 
constructable(sp?) Blob?


Could be.  Like I said, it's still in the editor's draft.


Also, should it not accept just ArrayBufferView then as per XMLHttpRequest?


Is there existing content depending on BlobBuilder and its 
ArrayBufferView stuff?


-Boris



Re: BlobBuilder.append() should take ArrayBufferView in addition to ArrayBuffer

2012-04-12 Thread Anne van Kesteren

On Thu, 12 Apr 2012 21:26:24 +0200, Boris Zbarsky  wrote:
This should make it easier to append limited views; appending the  
.buffer is a footgun because it appends the whole buffer.


Why are we still discussing BlobBuilder? I thought we discussed long ago  
it should be removed in favor of a constructable(sp?) Blob? Also, should  
it not accept just ArrayBufferView then as per XMLHttpRequest?



--
Anne van Kesteren
http://annevankesteren.nl/



BlobBuilder.append() should take ArrayBufferView in addition to ArrayBuffer

2012-04-12 Thread Boris Zbarsky
This should make it easier to append limited views; appending the 
.buffer is a footgun because it appends the whole buffer.


-Boris