# All files / serialization buffer.js

34.62% Statements 9/26
0% Branches 0/6
0% Functions 0/9
52.94% Lines 9/17

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
    1x
     import preArrayOf from './utils/pre-array-of'

    export const bufferFromJson = (obj) => Buffer.from(obj.data)

    export const bufferToJson = (buf) => ({
      __ipfsPostMsgProxyType: 'Buffer',
      data: Array.from(buf)
    })

    export const isBuffer = Buffer.isBuffer
    export const isBufferJson = (obj) => obj && obj.__ipfsPostMsgProxyType === 'Buffer'

    export const preBufferFromJson = (index) => {
      return (...args) => {
        if (isBufferJson(args[index])) {
          args[index] = bufferFromJson(args[index])
        }
        return args
      }
    }

    export const preBufferToJson = (index) => {
      return (...args) => {
        if (isBuffer(args[index])) {
          args[index] = bufferToJson(args[index])
        }
        return args
      }
    }

    export const preArrayOfBufferToJson = (index) => preArrayOf(index, isBuffer, bufferToJson)
    export const preArrayOfBufferFromJson = (index) => preArrayOf(index, isBufferJson, bufferFromJson)