# All files / src/serialization buffer.js

100% Statements 21/21
100% Branches 6/6
100% Functions 7/7
100% Lines 14/14

    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
    2811324x

    11324x

    1x
    51452x

    1x
    22214x
    11158x
    11045x

    11158x

    1x
    22214x
    11158x
    11045x

    11158x

     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
      }
    }