Re: [streams] How will ReadableByteStream work with seekable resources? (#253)

Could we use the revealing constructor pattern here again?  Something like:

```
var rbs = new ReadableByteStream({
  allocate: function() { return new ArrayBuffer(myPreferredSize); }
});
```

Then we don't need a new stream name. :-)

If we add a `free` hook, then you could build a block pool allocator strategy:

```
// use ping pong buffers
var blocks = [];
blocks[0] = new ArrayBuffer(4096);
blocks[1] = new ArrayBuffer(4096);

var rbs = new ReadableByteStream({
  allocate: function() { return blocks.pop(); },
  free: function(buf) { return blocks.push(buf); }
});
```

If we don't like confusing these attributes with the constructor "source" concept, then it could be set in a different method.  Something like:

```
var rbs = new ReadableByteStream(/*...*/);

// use ping pong buffers
var blocks = [];
blocks[0] = new ArrayBuffer(4096);
blocks[1] = new ArrayBuffer(4096);

rbs.setAllocator({
  allocate: function() { return blocks.pop(); },
  free: function(buf) { return blocks.push(buf); }
});
```

Would this address the problem?

---
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/streams/issues/253#issuecomment-73888200

Received on Wednesday, 11 February 2015 14:23:21 UTC