Example #1
0
module.exports.read = function(source, item_callback, done) {
	pull(
		source,
		bits.split([0x0A]),
		pull.asyncMap(function(cells, callback) {
			var was_async;
			var line = cells.toString();
			if (line[0] === '#') return callback();
			cells = line.split('\t');
			was_async = false;
			item_callback(cells, function(err) {
				cells = null;
				if (!was_async) {
					setImmediate(function() {
						callback(err);
					});
				} else {
					callback(err);
				}
			});
			was_async = true;
		}),
		pull.onEnd(done)
	);
};
Example #2
0
 const listener = tcp.createListener((conn) => {
   pull(
     pull.empty(),
     conn,
     pull.onEnd(closed)
   )
 })
Example #3
0
 listener.listen(ma, () => {
   pull(
     pull.empty(),
     tcp.dial(ma),
     pull.onEnd(destroyed)
   )
 })
Example #4
0
 it('dial to non existent listener', (done) => {
   const ma = multiaddr('/ip4/127.0.0.1/tcp/8989')
   pull(
     tcp.dial(ma),
     pull.onEnd((err) => {
       expect(err).to.exist()
       done()
     })
   )
 })
Example #5
0
File: get.js Project: ipfs/js-ipfs
      return new Promise((resolve, reject) => {
        const dir = checkArgs(ipfsPath, output)
        const stream = ipfs.getReadableStream(ipfsPath)

        print(`Saving file(s) ${ipfsPath}`)
        pull(
          toPull.source(stream),
          pull.asyncMap(fileHandler(dir)),
          pull.onEnd((err) => {
            if (err) return reject(err)
            resolve()
          })
        )
      })
Example #6
0
    listener.listen(ma, () => {
      const conn = ws.dial(ma)

      pull(
        pull.empty(),
        conn,
        pull.onEnd(onEnd)
      )

      function onEnd () {
        conn.getPeerInfo((err, peerInfo) => {
          expect(err).to.exist()
          listener.close(done)
        })
      }
    })
Example #7
0
    ipfs.files.getPull(key, (err, stream) => {
      if (err) {
        log.error(err)

        reply({
          Message: 'Failed to get file: ' + err,
          Code: 0
        }).code(500)
        return
      }

      pull(
        stream,
        pull.asyncMap((file, cb) => {
          const header = {name: file.path}

          if (!file.content) {
            header.type = 'directory'
            pack.entry(header)
            cb()
          } else {
            header.size = file.size
            toStream.source(file.content)
              .pipe(pack.entry(header, cb))
          }
        }),
        pull.onEnd((err) => {
          if (err) {
            log.error(err)

            reply({
              Message: 'Failed to get file: ' + err,
              Code: 0
            }).code(500)
            return
          }

          pack.finalize()
        })
      )

      // the reply must read the tar stream,
      // to pull values through
      reply(pack).header('X-Stream-Output', '1')
    })
Example #8
0
      setTimeout(function () {

        zip([pl.read(db), pl.read(_db)])
        .pipe(pull.through(function (data) {
          console.log(data)
          t.deepEqual(data[0], data[1])
        }))
        .pipe(pull.onEnd(function () {

          help.hash(db, function (err, hash) {
            help.hash(_db, function (err, _hash) {
              t.equal(hash, _hash)
              t.end()
            })
          })
        }))

      }, 200)
Example #9
0
    function onListen () {
      const conn = ws.dial(ma)
      conn.setPeerInfo('b')

      pull(
        pull.empty(),
        conn,
        pull.onEnd(onEnd)
      )

      function onEnd () {
        conn.getPeerInfo((err, peerInfo) => {
          expect(err).to.not.exist()
          expect(peerInfo).to.equal('b')
          listener.close(done)
        })
      }
    }
Example #10
0
    listener.listen(ma, () => {
      const conn = ws.dial(ma)

      pull(
        pull.empty(),
        conn,
        pull.onEnd(onEnd)
      )

      function onEnd () {
        conn.getObservedAddrs((err, addrs) => {
          expect(err).to.not.exist()
          listenerObsAddrs = addrs

          listener.close(onClose)

          function onClose () {
            expect(listenerObsAddrs[0]).to.deep.equal(ma)
            expect(dialerObsAddrs.length).to.equal(0)
            done()
          }
        })
      }
    })
Example #11
0
 const listener = tcp.createListener((conn) => {
   pull(conn, pull.onEnd(destroyed))
 })
Example #12
0
 listener.listen(ma, () => {
   pull(tcp.dial(ma), pull.onEnd(closed))
 })
Example #13
0
  describe: 'Fetch a file or directory with files references from an IPFS Path',

  builder: {
    output: {
      alias: 'o',
      type: 'string',
      default: process.cwd()
    }
  },

  handler (argv) {
    const ipfsPath = argv['ipfsPath']

    const dir = checkArgs(ipfsPath, argv.output)

    const stream = argv.ipfs.getReadableStream(ipfsPath)

    stream.once('error', (err) => {
      if (err) { throw err }
    })
    print(`Saving file(s) ${ipfsPath}`)
    pull(
      toPull.source(stream),
      pull.asyncMap(fileHandler(dir)),
      pull.onEnd((err) => {
        if (err) { throw err }
      })
    )
  }
}