# All files / lib/serialization block.js

100% Statements 31/31
91.67% Branches 11/12
100% Functions 9/9
100% Lines 31/31

    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
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63

    1x

    1x

    1x

    1x

    1x

    1x

    1x

    1x
    7x

    1x
    7x
    7x
    7x

    1x
    5x

    1x
    5x

    1x
    19x
    5x
    7x

    5x
    1x

    5x

    1x
    19x
    5x
    7x

    5x
    1x

    5x

     'use strict';

    Object.defineProperty(exports, "__esModule", {
      value: true
    });
    exports.preBlockToJson = exports.preBlockFromJson = exports.isBlockJson = exports.isBlock = exports.blockFromJson = exports.blockToJson = undefined;

    var _ipfsBlock = require('ipfs-block');

    var _ipfsBlock2 = _interopRequireDefault(_ipfsBlock);

    var _cid = require('./cid');

    var _buffer = require('./buffer');

    function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

    var blockToJson = exports.blockToJson = function blockToJson(block) {
      return {
        __ipfsPostMsgProxyType: 'Block',
        cid: (0, _cid.cidToJson)(block.cid),
        data: (0, _buffer.bufferToJson)(block.data)
      };
    };

    var blockFromJson = exports.blockFromJson = function blockFromJson(obj) {
      var cid = (0, _cid.cidFromJson)(obj.cid);
      var data = (0, _buffer.bufferFromJson)(obj.data);
      return new _ipfsBlock2.default(data, cid);
    };

    var isBlock = exports.isBlock = function isBlock(obj) {
      return obj && _ipfsBlock2.default.isBlock(obj);
    };
    var isBlockJson = exports.isBlockJson = function isBlockJson(obj) {
      return obj && obj.__ipfsPostMsgProxyType === 'Block';
    };

    var preBlockFromJson = exports.preBlockFromJson = function preBlockFromJson(index) {
      return function () {
        for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
          args[_key] = arguments[_key];
        }

        if (isBlockJson(args[index])) {
          args[index] = blockFromJson(args[index]);
        }
        return args;
      };
    };

    var preBlockToJson = exports.preBlockToJson = function preBlockToJson(index) {
      return function () {
        for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
          args[_key2] = arguments[_key2];
        }

        if (isBlock(args[index])) {
          args[index] = blockToJson(args[index]);
        }
        return args;
      };
    };