# All files / src/server/files ls.js

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

    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

    23x

    3x

    2x
    2x
    2x
    2x
    2x

     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.files.ls', pre(
          preBufferFromJson(0),
          preCidFromJson(0),
          opts.pre('files.ls'),
          (...args) => getIpfs().ls(...args)
        ), opts),
        lsPullStream: expose('ipfs.files.lsPullStream', pre(
          preBufferFromJson(0),
          preCidFromJson(0),
          opts.pre('files.lsPullStream'),
          post(
            (...args) => getIpfs().lsPullStream(...args),
            (res) => new Promise(resolve => {
              const readFnName = shortid()
              pull(res, PMS.sink(readFnName, opts))
              resolve(functionToJson(readFnName))
            })
          )
        ), opts)
      }
    }