Commit 71f686622a5db9cf61e832d8abb372970f5752d4
implement ls stream in terms of pull-live
Dominic Tarr committed on 5/20/2016, 7:12:55 AMParent: 6027d0f68dd4a7385c9d5a573f73af734303dafd
Files changed
index.js | changed |
index.js | ||
---|---|---|
@@ -9,9 +9,9 @@ | ||
9 | 9 | var glob = require('pull-glob') |
10 | 10 | var paramap = require('pull-paramap') |
11 | 11 | var cat = require('pull-cat') |
12 | 12 | var Notify = require('pull-notify') |
13 | - | |
13 | +var Live = require('pull-live') | |
14 | 14 | var Write = require('pull-write-file') |
15 | 15 | var Read = require('pull-file') |
16 | 16 | |
17 | 17 | var u = require('./util') |
@@ -226,43 +226,32 @@ | ||
226 | 226 | }) |
227 | 227 | |
228 | 228 | return deferred |
229 | 229 | }, |
230 | - ls: function (opts) { | |
231 | - opts = opts || {} | |
232 | - var isOld = opts.old !== false | |
233 | - var isLive = opts.live === true || opts.old === false | |
234 | 230 | |
235 | - if(!isLive && !isOld) | |
236 | - throw new Error('ls with neither old or new is empty') | |
237 | - | |
231 | + ls: Live(function old (opts) { | |
238 | 232 | var long = (opts.size || opts.long || opts.meta) |
239 | - var old = pull( | |
233 | + return pull( | |
240 | 234 | glob(path.join(dir, '*', '*', '*')), |
241 | 235 | long ? paramap(function (filename, cb) { |
242 | 236 | stat(filename, function (err, stat) { |
243 | 237 | cb(err, toMeta(toHash(filename), stat)) |
244 | 238 | }) |
245 | 239 | }, 32) : pull.map(toHash) |
246 | 240 | ) |
247 | - | |
248 | - if(!isLive) return old | |
249 | - | |
250 | - var live = long | |
241 | + }, function live (opts) { | |
242 | + var long = (opts.size || opts.long || opts.meta) | |
243 | + return long | |
251 | 244 | ? newBlob.listen() |
252 | 245 | : pull(newBlob.listen(), pull.map(function (e) { return e.id })) |
246 | + }), | |
253 | 247 | |
254 | - if(!isOld) return live | |
255 | - | |
256 | - //old & live | |
257 | - return cat([old, pull.once({sync: true}), live]) | |
258 | - }, | |
259 | 248 | rm: function (hash, cb) { |
260 | 249 | fs.unlink(toPath(dir, hash), cb) |
261 | 250 | }, |
251 | + | |
262 | 252 | resolve: function (hash) { |
263 | 253 | return toPath(dir, hash) |
264 | 254 | } |
265 | 255 | } |
266 | 256 | } |
267 | 257 | |
268 | - |
Built with git-ssb-web