Re: Overlap between StreamReader and FileReader

I wrote a strawman spec for Stream.readAsArrayBuffer. Comment please.

interface Stream {
  AbortableProgressPromise<ArrayBuffer> readAsArrayBuffer(
    optional unsigned long long size);

When the readAsArrayBuffer(size) method is called on a stream, the user
agent must run the steps below.

1. If the stream has been neutered, throw an InvalidStateError exception
and terminate this algorithm.
2. Let *promise* be an AbortableProgressPromise of ArrayBuffer and *resolver
* be *promise*'s associated resolver.
3. Let *read_position* be read_position of stream.
4. If called with the optional *size*, set the read_position of stream to
read_position + *size*.
5. Otherwise, neuter the *stream*.
6. Return the readAsArrayBuffer with *promise*, but continue to process the
steps in this algorithm.
7. Read data from *stream* from *read_position* up to *size* bytes or all
data is *size* is not specified.
8. As data from the stream becomes available, do the following,
  1. Create an *arraybuffer* from the data.
  2. User agents should release resource of the *stream* for storing the
read data.
  3. If any error has occurred, call reject of *resolver* with a DOMError
object that indicates the kind of stream error that has occurred, and
terminate this algorithm.
  4. If the end of data is reached or the total number of bytes read for
this algorithm reaches *size*, call fullfil of *resolver* with the *
arraybuffer* and terminate this algorithm.
  5. Otherwise, call progress of *resolver* with the *arraybuffer*.

Received on Wednesday, 26 June 2013 05:48:55 UTC