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 /lib/util.js | |
parent | fd460396edec6969e0dae683021a7bda577f6d79 (diff) | |
download | patchfoo-b66bcecec258b0a2631ec338501afa9409882fe8.tar.gz patchfoo-b66bcecec258b0a2631ec338501afa9409882fe8.zip |
Slice packfiles manually
Support vanilla multiblob
Diffstat (limited to 'lib/util.js')
-rw-r--r-- | lib/util.js | 28 |
1 files changed, 28 insertions, 0 deletions
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))) + }) + } + } +} |