aboutsummaryrefslogtreecommitdiff
path: root/lib/util.js
diff options
context:
space:
mode:
authorcel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2017-05-28 18:42:44 -1000
committercel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2017-05-28 18:42:44 -1000
commitb66bcecec258b0a2631ec338501afa9409882fe8 (patch)
treea321f0fc90439c64f9210c9d459513016878c994 /lib/util.js
parentfd460396edec6969e0dae683021a7bda577f6d79 (diff)
downloadpatchfoo-b66bcecec258b0a2631ec338501afa9409882fe8.tar.gz
patchfoo-b66bcecec258b0a2631ec338501afa9409882fe8.zip
Slice packfiles manually
Support vanilla multiblob
Diffstat (limited to 'lib/util.js')
-rw-r--r--lib/util.js28
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, '&lt;')
.replace(/>/g, '&gt;')
}
+
+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)))
+ })
+ }
+ }
+}