All files / client ls.js

63.16% Statements 12/19
100% Branches 0/0
16.67% Functions 1/6
63.16% Lines 12/19

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 461x 1x 1x 1x 1x 1x 1x 1x     39x                       39x                 39x                       39x    
import { caller } from 'postmsg-rpc'
import callbackify from 'callbackify'
import defer from 'pull-defer'
import toStream from 'pull-stream-to-stream'
import PMS from 'pull-postmsg-stream'
import { pre, post } from 'prepost'
import { preCidToJson } from '../serialization/cid'
import { preBufferToJson } from '../serialization/buffer'
 
export default function (opts) {
  const api = {
    ls: callbackify.variadic(
      pre(
        preBufferToJson(0),
        preCidToJson(0),
        caller('ipfs.ls', opts)
      )
    ),
    lsReadableStream () {
      return toStream.source(api.lsPullStream(...arguments))
    },
    lsPullStream: (() => {
      const lsPullStream = pre(
        preBufferToJson(0),
        preCidToJson(0),
        post(
          caller('ipfs.lsPullStream', opts),
          (res) => PMS.source(res.name, opts)
        )
      )
 
      return (...args) => {
        const deferred = defer.source()
 
        lsPullStream(...args)
          .then((res) => deferred.resolve(res))
          .catch((err) => deferred.abort(err))
 
        return deferred
      }
    })()
  }
 
  return api
}