# All files / lib/client/files get.js

97.56% Statements 40/41
75% Branches 9/12
92.31% Functions 12/13
97.56% Lines 40/41

    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
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91

    1x

    1x
    19x

    6x
    15x
    11x

    15x

    1x
    1x
    1x

    1x

    19x
    2x
    2x
    2x

    4x
    2x

    4x

    2x

    19x
    2x

    2x
    2x

    2x

    19x

    1x

    1x

    1x

    1x

    1x

    1x

    1x

    1x

    1x

    1x

    1x

    1x

    1x

    1x

    5x'use strict';

    Object.defineProperty(exports, "__esModule", {
      value: true
    });

    exports.default = function (opts) {
      var api = {
        get: _callbackify2.default.variadic((0, _prepost.pre)((0, _buffer.preBufferToJson)(0), (0, _cid.preCidToJson)(0), (0, _prepost.post)((0, _postmsgRpc.caller)('ipfs.files.get', opts), function (files) {
          return files.map(function (file) {
            if (file.content) {
              file.content = (0, _buffer.bufferFromJson)(file.content);
            }

            return file;
          });
        }))),
        getReadableStream: function getReadableStream() {
          return _pullStreamToStream2.default.source((0, _pullStream2.default)(api.getPullStream.apply(api, arguments), _pullStream2.default.map(function (file) {
            Eif (file.content) {
              file.content = _pullStreamToStream2.default.source(file.content);
            }
            return file;
          })));
        },

        getPullStream: function () {
          var getPullStream = (0, _prepost.pre)((0, _buffer.preBufferToJson)(0), (0, _cid.preCidToJson)(0), (0, _prepost.post)((0, _postmsgRpc.caller)('ipfs.files.getPullStream', opts), function (res) {
            return (0, _pullStream2.default)(_pullPostmsgStream2.default.source(res.name, opts), _pullStream2.default.map(function (file) {
              Eif (file.content) {
                file.content = _pullPostmsgStream2.default.source(file.content.name, Object.assign({}, opts, {
                  post: function post(res) {
                    if ((0, _buffer.isBufferJson)(res.data)) {
                      res.data = (0, _buffer.bufferFromJson)(res.data);
                    }

                    return res;
                  }
                }));
              }

              return file;
            }));
          }));

          return function () {
            var deferred = _pullDefer2.default.source();

            getPullStream.apply(undefined, arguments).then(function (res) {
              return deferred.resolve(res);
            }).catch(function (err) {
              return deferred.abort(err);
            });

            return deferred;
          };
        }()
      };

      return api;
    };

    var _postmsgRpc = require('postmsg-rpc');

    var _callbackify = require('callbackify');

    var _callbackify2 = _interopRequireDefault(_callbackify);

    var _pullDefer = require('pull-defer');

    var _pullDefer2 = _interopRequireDefault(_pullDefer);

    var _pullStream = require('pull-stream');

    var _pullStream2 = _interopRequireDefault(_pullStream);

    var _pullStreamToStream = require('pull-stream-to-stream');

    var _pullStreamToStream2 = _interopRequireDefault(_pullStreamToStream);

    var _pullPostmsgStream = require('pull-postmsg-stream');

    var _pullPostmsgStream2 = _interopRequireDefault(_pullPostmsgStream);

    var _prepost = require('prepost');

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

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

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