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) ); };
const listener = tcp.createListener((conn) => { pull( pull.empty(), conn, pull.onEnd(closed) ) })
listener.listen(ma, () => { pull( pull.empty(), tcp.dial(ma), pull.onEnd(destroyed) ) })
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() }) ) })
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() }) ) })
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) }) } })
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') })
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)
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) }) } }
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() } }) } })
const listener = tcp.createListener((conn) => { pull(conn, pull.onEnd(destroyed)) })
listener.listen(ma, () => { pull(tcp.dial(ma), pull.onEnd(closed)) })
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 } }) ) } }