Skip to content

Instantly share code, notes, and snippets.

@nothingmuch
Created August 20, 2017 23:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nothingmuch/f7110106054ea3894b1173c3cc67d0db to your computer and use it in GitHub Desktop.
Save nothingmuch/f7110106054ea3894b1173c3cc67d0db to your computer and use it in GitHub Desktop.
diff --git a/index.js b/index.js
index 5bacf9d..fee9969 100644
--- a/index.js
+++ b/index.js
@@ -98,6 +98,7 @@ Store.prototype._write = function (offset, buf, cb) {
var offsets = self._blocks(offset, offset + buf.length)
var pending = 1
var buffers = {}
+
for (var i = 0; i < offsets.length; i++) (function (o,i) {
if (o.end-o.start === self.size) return
pending++
@@ -108,6 +109,7 @@ Store.prototype._write = function (offset, buf, cb) {
if (--pending === 0) write(store, offsets, buffers)
})
})(offsets[i],i)
+
if (--pending === 0) write(store, offsets, buffers)
})
function write (store, offsets, buffers) {
@@ -123,13 +125,19 @@ Store.prototype._write = function (offset, buf, cb) {
store.put(block,self.name + DELIM + o.block)
j += len
}
+
+ backify(store.get(self.name + DELIM + "length"), function(err, ev) {
+ self.length = Math.max(self.length, ev.target.result|| 0)
var length = Math.max(self.length || 0, offset + buf.length)
store.put(length, self.name + DELIM + "length")
+
store.transaction.addEventListener('complete', function () {
self.length = length
cb(null)
})
+
store.transaction.addEventListener('error', cb)
+ })
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment