git ssb

16+

cel / patchfoo



Commit b66bcecec258b0a2631ec338501afa9409882fe8

Slice packfiles manually

Support vanilla multiblob
cel committed on 5/29/2017, 4:42:44 AM
Parent: fd460396edec6969e0dae683021a7bda577f6d79

Files changed

lib/app.jschanged
lib/git.jschanged
lib/util.jschanged
lib/app.jsView
@@ -176,28 +176,35 @@
176176 var addCb = done()
177177 done(function (err, hash, add) {
178178 cb(err, hash)
179179 })
180- return pull(
181- hasher(hashCb),
182- this.sbot.blobs.add(addCb)
183- )
180 + return sink
184181 }
185182
186183 App.prototype.pushBlob = function (id, cb) {
187184 console.error('pushing blob', id)
188185 this.sbot.blobs.push(id, cb)
189186 }
190187
191-App.prototype.readBlob = function (link, opts) {
188 +App.prototype.readBlob = function (link) {
192189 link = u.toLink(link)
193- opts = opts || {}
194190 return this.sbot.blobs.get({
195191 hash: link.link,
196192 size: link.size,
193 + })
194 +}
195 +
196 +App.prototype.readBlobSlice = function (link, opts) {
197 + if (this.sbot.blobs.getSlice) return this.sbot.blobs.getSlice({
198 + hash: link.link,
199 + size: link.size,
197200 start: opts.start,
198201 end: opts.end,
199202 })
203 + return pull(
204 + this.readBlob(link),
205 + u.pullSlice(opts.start, opts.end)
206 + )
200207 }
201208
202209 App.prototype.ensureHasBlobs = function (links, cb) {
203210 var self = this
lib/git.jsView
@@ -81,9 +81,9 @@
8181 }
8282
8383 Git.prototype.readObject = function (obj) {
8484 return pull(
85- this.app.readBlob(obj.packLink, {start: obj.offset, end: obj.next}),
85 + this.app.readBlobSlice(obj.packLink, {start: obj.offset, end: obj.next}),
8686 this.decodeObject({
8787 type: obj.type,
8888 length: obj.length,
8989 packLink: obj.packLink,
@@ -309,9 +309,9 @@
309309 var offset = opts.idx.find(sourceHash)
310310 if (!offset) return cb(null, 'missing source object ' +
311311 sourcehash.toString('hex'))
312312 var readSource = pull(
313- self.app.readBlob(opts.packLink, {
313 + self.app.readBlobSlice(opts.packLink, {
314314 start: offset.offset,
315315 end: offset.next
316316 }),
317317 self.decodeObject({
lib/util.jsView
@@ -140,4 +140,32 @@
140140 return html.toString('utf8')
141141 .replace(/</g, '&lt;')
142142 .replace(/>/g, '&gt;')
143143 }
144 +
145 +u.pullSlice = function (start, end) {
146 + if (end == null) end = Infinity
147 + var offset = 0
148 + return function (read) {
149 + return function (abort, cb) {
150 + if (abort) read(abort, cb)
151 + else if (offset >= end) read(true, function (err) {
152 + cb(err || true)
153 + })
154 + else if (offset < start) read(null, function next(err, data) {
155 + if (err) return cb(err)
156 + offset += data.length
157 + if (offset <= start) read(null, next)
158 + else if (offset < end) cb(null,
159 + data.slice(data.length - (offset - start)))
160 + else cb(null, data.slice(data.length - (offset - start),
161 + data.length - (offset - end)))
162 + })
163 + else read(null, function (err, data) {
164 + if (err) return cb(err)
165 + offset += data.length
166 + if (offset <= end) cb(null, data)
167 + else cb(null, data.slice(0, data.length - (offset - end)))
168 + })
169 + }
170 + }
171 +}

Built with git-ssb-web