From db64115882bbe712c3de7f624b50b60858847ede Mon Sep 17 00:00:00 2001 From: Pedro Teixeira Date: Fri, 24 Mar 2017 09:50:24 +0000 Subject: [PATCH 1/5] fix: pull-stream-to-stream replaced with duplex stream because of end event --- src/core/components/files.js | 41 +++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/src/core/components/files.js b/src/core/components/files.js index 7f142edf18..fb0319f8e9 100644 --- a/src/core/components/files.js +++ b/src/core/components/files.js @@ -8,11 +8,13 @@ const promisify = require('promisify-es6') const multihashes = require('multihashes') const pull = require('pull-stream') const sort = require('pull-sort') +const pushable = require('pull-pushable') const toStream = require('pull-stream-to-stream') const toPull = require('stream-to-pull-stream') const CID = require('cids') const waterfall = require('async/waterfall') const isStream = require('isstream') +const Duplex = require('stream').Duplex module.exports = function files (self) { const createAddPullStream = (options) => { @@ -30,7 +32,19 @@ module.exports = function files (self) { callback = options options = undefined } - callback(null, toStream(createAddPullStream(options))) + + const addPullStream = createAddPullStream(options) + const p = pushable() + const s = pull( + p, + addPullStream + ) + + const retStream = new AddStreamDuplex(s, p) + + retStream.once('finish', () => p.end()) + + callback(null, retStream) }, createAddPullStream: createAddPullStream, @@ -164,3 +178,28 @@ function normalizeContent (content) { } function noop () {} + +class AddStreamDuplex extends Duplex { + constructor (pullStream, push, options) { + super(Object.assign({}, { objectMode: true }, options)) + this._pullStream = pullStream + this._pushable = push + } + + _read () { + this._pullStream(null, (err, data) => { + if (err) { + if (err instanceof Error) { + this.emit('error', err) + } + } else { + this.push(data) + } + }) + } + + _write (chunk, encoding, callback) { + this._pushable.push(chunk) + callback() + } +} From e16c48e9aace802156e5f958fd91c7e65e50a1d7 Mon Sep 17 00:00:00 2001 From: Pedro Teixeira Date: Fri, 24 Mar 2017 10:46:13 +0000 Subject: [PATCH 2/5] minor aesthetic fixes on files.createAddstream --- src/core/components/files.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/core/components/files.js b/src/core/components/files.js index fb0319f8e9..3c371da981 100644 --- a/src/core/components/files.js +++ b/src/core/components/files.js @@ -181,16 +181,16 @@ function noop () {} class AddStreamDuplex extends Duplex { constructor (pullStream, push, options) { - super(Object.assign({}, { objectMode: true }, options)) + super(Object.assign({ objectMode: true }, options)) this._pullStream = pullStream this._pushable = push } _read () { - this._pullStream(null, (err, data) => { - if (err) { - if (err instanceof Error) { - this.emit('error', err) + this._pullStream(null, (end, data) => { + if (end) { + if (end instanceof Error) { + this.emit('error', end) } } else { this.push(data) From 3ae85688ce7ff8dc99097907afb900ee3655a3ad Mon Sep 17 00:00:00 2001 From: Pedro Teixeira Date: Fri, 24 Mar 2017 10:47:04 +0000 Subject: [PATCH 3/5] chore: documenting sharding experimental feature --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 229da0378b..121164bec9 100644 --- a/README.md +++ b/README.md @@ -232,7 +232,8 @@ const node = new IPFS({ start: true, // start: false, EXPERIMENTAL: { // enable experimental features - pubsub: true + pubsub: true, + sharding: true // enable dir sharding }, config: { // overload the default config Addresses: { From 9b16c025646fae1935cdfcb9667ed31053362c9e Mon Sep 17 00:00:00 2001 From: Pedro Teixeira Date: Fri, 24 Mar 2017 10:53:34 +0000 Subject: [PATCH 4/5] chore: dep update --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 59e29db7cc..82c43103d7 100644 --- a/package.json +++ b/package.json @@ -108,7 +108,7 @@ "ipfs-multipart": "~0.1.0", "ipfs-repo": "~0.13.0", "ipfs-unixfs": "~0.1.11", - "ipfs-unixfs-engine": "~0.18.0", + "ipfs-unixfs-engine": "~0.19.0", "ipld-resolver": "~0.11.0", "isstream": "^0.1.2", "joi": "^10.3.0", @@ -139,7 +139,7 @@ "pull-stream-to-stream": "^1.3.3", "pull-zip": "^2.0.1", "read-pkg-up": "^2.0.0", - "readable-stream": "1.1.14", + "readable-stream": "2.2.6", "safe-buffer": "^5.0.1", "stream-to-pull-stream": "^1.7.2", "tar-stream": "^1.5.2", From a1a3937955db3bfa3c008644cd19ab0c24e8eca9 Mon Sep 17 00:00:00 2001 From: Pedro Teixeira Date: Fri, 24 Mar 2017 10:57:46 +0000 Subject: [PATCH 5/5] fix: corrected readable stream version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 82c43103d7..ca27039d3d 100644 --- a/package.json +++ b/package.json @@ -139,7 +139,7 @@ "pull-stream-to-stream": "^1.3.3", "pull-zip": "^2.0.1", "read-pkg-up": "^2.0.0", - "readable-stream": "2.2.6", + "readable-stream": "1.1.14", "safe-buffer": "^5.0.1", "stream-to-pull-stream": "^1.7.2", "tar-stream": "^1.5.2",