All files / server block.js

100% Statements 14/14
100% Branches 4/4
100% Functions 4/4
100% Lines 13/13

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 421x 1x 1x 1x 1x     39x       11x 8x 1x     8x       8x                 4x               1x        
import { expose } from 'postmsg-rpc'
import { pre, post } from 'prepost'
import { blockToJson, preBlockFromJson } from '../serialization/block'
import { preCidFromJson, cidFromJson } from '../serialization/cid'
import { preBufferFromJson } from '../serialization/buffer'
 
export default function (getIpfs, opts) {
  return {
    put: expose('ipfs.block.put', pre(
      preBufferFromJson(0),
      preBlockFromJson(0),
      (...args) => {
        if (args[1] && args[1].cid) {
          args[1].cid = cidFromJson(args[1].cid)
        }
 
        return args
      },
      opts.pre('block.put'),
      post(
        (...args) => getIpfs().block.put(...args),
        blockToJson
      )
    ), opts),
    get: expose('ipfs.block.get', pre(
      preBufferFromJson(0),
      preCidFromJson(0),
      opts.pre('block.get'),
      post(
        (...args) => getIpfs().block.get(...args),
        blockToJson
      )
    ), opts),
    stat: expose('ipfs.block.stat', pre(
      preBufferFromJson(0),
      preCidFromJson(0),
      opts.pre('block.stat'),
      (...args) => getIpfs().block.stat(...args)
    ), opts)
  }
}