Re: Overlap between StreamReader and FileReader

On Sat, May 18, 2013 at 1:56 PM, Jonas Sicking <jonas@sicking.cc> wrote:

> On Fri, May 17, 2013 at 9:38 PM, Jonas Sicking <jonas@sicking.cc> wrote:
> > For Stream reading, I think I would do something like the following:
> >
> > interface Stream {
> >   AbortableProgressFuture<ArrayBuffer> readBinary(optional unsigned
> > long long size);
> >   AbortableProgressFuture<String> readText(optional unsigned long long
> > size, optional DOMString encoding);
> >   AbortableProgressFuture<Blob> readBlob(optional unsigned long long
> size);
> >
> >   ChunkedData readBinaryChunked(optional unsigned long long size);
> >   ChunkedData readTextChunked(optional unsigned long long size);
> > };
> >
> > interface ChunkedData : EventTarget {
> >   attribute EventHandler ondata;
> >   attribute EventHandler onload;
> >   attribute EventHandler onerror;
> > };
>
> Actually, we could even get rid of the ChunkedData interface and do
> something like
>
> interface Stream {
>   AbortableProgressFuture<ArrayBuffer> readBinary(optional unsigned
> long long size);
>   AbortableProgressFuture<String> readText(optional unsigned long long
> size, optional DOMString encoding);
>   AbortableProgressFuture<Blob> readBlob(optional unsigned long long size);
>
>   AbortableProgressFuture<void> readBinaryChunked(optional unsigned
> long long size);
>   AbortableProgressFuture<void> readTextChunked(optional unsigned long
> long size);
> };
>
> where the ProgressFutures returned from
> readBinaryChunked/readBinaryChunked delivers the data in the progress
> notifications only, and no data is delivered when the future is
> actually resolved. Though this might be abusing Futures a bit?
>

This is also clear read-only-once interface as well as onmessage() approach
because there's no attribute to accumulate the result value. The fact that
the argument for accept callback is void strikes at least me that the value
passed to progress callback is not an accumulated result but each chunk
separately.

As the state transition of Stream would be simple enough to match Future, I
think technically it's ok and even better to employ it than "readyState +
callback" approach.

But is everyone fine with making it mandatory to get used to programming
with Future to use Stream?

Received on Saturday, 18 May 2013 08:28:30 UTC