abstract-blob-store
abstract-blob-store copied to clipboard
createReadStream behaviour before closing stream from createWriteStream
trafficstars
Using a test over at memory-blob-store to specify the behaviour of calling createReadStream from a key that has an open Writable returned from createWriteStream:
test('handles multiple readers during write stream', function(t) {
var key = 'foobar';
var data = ['x', 'y', 'z'];
var index = 0;
t.plan(data.length * 2);
setup(null, function (e, store) {
var ws = store.createWriteStream(key);
var rs1 = store.createReadStream(key);
var rs2 = store.createReadStream(key);
rs1.on('data', function(d) {
t.equal(d.toString(), data[index | 0], 'Received data during write');
index += .5;
});
rs2.on('data', function(d) {
t.equal(d.toString(), data[index | 0], 'Received data during write');
index += .5;
});
for(var i = 0; i < data.length; i++) {
ws.write(data[i]);
}
});
});
I'm not sure what the abstract-blob-store standard is for handling this case or if it is intentionally left up to the implementer.
IMO that should error, data should not be available until the write stream has finished.
But that could be hard to do for some implementations so I think we would be better off leaving it to the implementer