chunk-store-stream
Advanced tools
Comparing version 3.0.1 to 4.0.0
{ | ||
"name": "chunk-store-stream", | ||
"description": "Convert an abstract-chunk-store compliant store into a readable or writable stream", | ||
"version": "3.0.1", | ||
"version": "4.0.0", | ||
"author": { | ||
@@ -15,3 +15,3 @@ "name": "Feross Aboukhadijeh", | ||
"block-stream2": "^1.0.0", | ||
"readable-stream": "^2.0.5" | ||
"readable-stream": "^3.4.0" | ||
}, | ||
@@ -25,3 +25,3 @@ "devDependencies": { | ||
"standard": "*", | ||
"string-to-stream": "^1.0.1", | ||
"string-to-stream": "^2.0.0", | ||
"tape": "^4.1.0" | ||
@@ -28,0 +28,0 @@ }, |
21
write.js
@@ -15,2 +15,3 @@ const BlockStream = require('block-stream2') | ||
this._blockstream = new BlockStream(chunkLength, { zeroPadding: false }) | ||
this._outstandingPuts = 0 | ||
@@ -20,3 +21,11 @@ let index = 0 | ||
if (this.destroyed) return | ||
store.put(index, chunk) | ||
this._outstandingPuts += 1 | ||
store.put(index, chunk, () => { | ||
this._outstandingPuts -= 1 | ||
if (this._outstandingPuts === 0 && typeof this._finalCb === 'function') { | ||
this._finalCb(null) | ||
this._finalCb = null | ||
} | ||
}) | ||
index += 1 | ||
@@ -28,4 +37,2 @@ } | ||
.on('error', err => { this.destroy(err) }) | ||
this.on('finish', () => this._blockstream.end()) | ||
} | ||
@@ -37,2 +44,10 @@ | ||
_final (cb) { | ||
this._blockstream.end() | ||
this._blockstream.once('end', () => { | ||
if (this._outstandingPuts === 0) cb(null) | ||
else this._finalCb = cb | ||
}) | ||
} | ||
destroy (err) { | ||
@@ -39,0 +54,0 @@ if (this.destroyed) return |
7020
85
+ Addedreadable-stream@3.6.2(transitive)
Updatedreadable-stream@^3.4.0