All files / server ls.js

60% Statements 9/15
100% Branches 0/0
0% Functions 0/4
60% Lines 9/15

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 331x 1x 1x 1x 1x 1x 1x 1x     39x                                            
import { expose } from 'postmsg-rpc'
import { pre, post } from 'prepost'
import pull from 'pull-stream'
import PMS from 'pull-postmsg-stream'
import shortid from 'shortid'
import { preCidFromJson } from '../serialization/cid'
import { preBufferFromJson } from '../serialization/buffer'
import { functionToJson } from '../serialization/function'
 
export default function (getIpfs, opts) {
  return {
    ls: expose('ipfs.ls', pre(
      preBufferFromJson(0),
      preCidFromJson(0),
      opts.pre('ls'),
      (...args) => getIpfs().ls(...args)
    ), opts),
    lsPullStream: expose('ipfs.lsPullStream', pre(
      preBufferFromJson(0),
      preCidFromJson(0),
      opts.pre('lsPullStream'),
      post(
        (...args) => getIpfs().lsPullStream(...args),
        (res) => new Promise((resolve) => {
          const readFnName = shortid()
          pull(res, PMS.sink(readFnName, opts))
          resolve(functionToJson(readFnName))
        })
      )
    ), opts)
  }
}