diff options
author | cel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519> | 2017-05-28 18:42:44 -1000 |
---|---|---|
committer | cel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519> | 2017-05-28 18:42:44 -1000 |
commit | b66bcecec258b0a2631ec338501afa9409882fe8 (patch) | |
tree | a321f0fc90439c64f9210c9d459513016878c994 | |
parent | fd460396edec6969e0dae683021a7bda577f6d79 (diff) | |
download | patchfoo-b66bcecec258b0a2631ec338501afa9409882fe8.tar.gz patchfoo-b66bcecec258b0a2631ec338501afa9409882fe8.zip |
Slice packfiles manually
Support vanilla multiblob
-rw-r--r-- | lib/app.js | 19 | ||||
-rw-r--r-- | lib/git.js | 4 | ||||
-rw-r--r-- | lib/util.js | 28 |
3 files changed, 43 insertions, 8 deletions
@@ -177,10 +177,7 @@ App.prototype.addBlob = function (cb) { done(function (err, hash, add) { cb(err, hash) }) - return pull( - hasher(hashCb), - this.sbot.blobs.add(addCb) - ) + return sink } App.prototype.pushBlob = function (id, cb) { @@ -188,15 +185,25 @@ App.prototype.pushBlob = function (id, cb) { this.sbot.blobs.push(id, cb) } -App.prototype.readBlob = function (link, opts) { +App.prototype.readBlob = function (link) { link = u.toLink(link) - opts = opts || {} return this.sbot.blobs.get({ hash: link.link, size: link.size, + }) +} + +App.prototype.readBlobSlice = function (link, opts) { + if (this.sbot.blobs.getSlice) return this.sbot.blobs.getSlice({ + hash: link.link, + size: link.size, start: opts.start, end: opts.end, }) + return pull( + this.readBlob(link), + u.pullSlice(opts.start, opts.end) + ) } App.prototype.ensureHasBlobs = function (links, cb) { @@ -82,7 +82,7 @@ Git.prototype.openObject = function (opts, cb) { Git.prototype.readObject = function (obj) { return pull( - this.app.readBlob(obj.packLink, {start: obj.offset, end: obj.next}), + this.app.readBlobSlice(obj.packLink, {start: obj.offset, end: obj.next}), this.decodeObject({ type: obj.type, length: obj.length, @@ -310,7 +310,7 @@ Git.prototype.decodeObject = function (opts) { if (!offset) return cb(null, 'missing source object ' + sourcehash.toString('hex')) var readSource = pull( - self.app.readBlob(opts.packLink, { + self.app.readBlobSlice(opts.packLink, { start: offset.offset, end: offset.next }), diff --git a/lib/util.js b/lib/util.js index e8fc435..d25ecaf 100644 --- a/lib/util.js +++ b/lib/util.js @@ -141,3 +141,31 @@ u.escapeHTML = function (html) { .replace(/</g, '<') .replace(/>/g, '>') } + +u.pullSlice = function (start, end) { + if (end == null) end = Infinity + var offset = 0 + return function (read) { + return function (abort, cb) { + if (abort) read(abort, cb) + else if (offset >= end) read(true, function (err) { + cb(err || true) + }) + else if (offset < start) read(null, function next(err, data) { + if (err) return cb(err) + offset += data.length + if (offset <= start) read(null, next) + else if (offset < end) cb(null, + data.slice(data.length - (offset - start))) + else cb(null, data.slice(data.length - (offset - start), + data.length - (offset - end))) + }) + else read(null, function (err, data) { + if (err) return cb(err) + offset += data.length + if (offset <= end) cb(null, data) + else cb(null, data.slice(0, data.length - (offset - end))) + }) + } + } +} |