abstract-blob-store icon indicating copy to clipboard operation
abstract-blob-store copied to clipboard

createReadStream behaviour before closing stream from createWriteStream

Open retrohacker opened this issue 8 years ago • 1 comments
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.

retrohacker avatar Feb 02 '17 22:02 retrohacker

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

jnordberg avatar Oct 07 '17 07:10 jnordberg