Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Commit 4b064a1

Browse files
pgtedaviddias
authored andcommitted
fix: pull-stream-to-stream replaced with duplex stream (#809)
* fix: pull-stream-to-stream replaced with duplex stream because of end event
1 parent 835e993 commit 4b064a1

File tree

3 files changed

+43
-3
lines changed

3 files changed

+43
-3
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,8 @@ const node = new IPFS({
232232
start: true,
233233
// start: false,
234234
EXPERIMENTAL: { // enable experimental features
235-
pubsub: true
235+
pubsub: true,
236+
sharding: true // enable dir sharding
236237
},
237238
config: { // overload the default config
238239
Addresses: {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@
108108
"ipfs-multipart": "~0.1.0",
109109
"ipfs-repo": "~0.13.0",
110110
"ipfs-unixfs": "~0.1.11",
111-
"ipfs-unixfs-engine": "~0.18.0",
111+
"ipfs-unixfs-engine": "~0.19.0",
112112
"ipld-resolver": "~0.11.0",
113113
"isstream": "^0.1.2",
114114
"joi": "^10.3.0",

src/core/components/files.js

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ const promisify = require('promisify-es6')
88
const multihashes = require('multihashes')
99
const pull = require('pull-stream')
1010
const sort = require('pull-sort')
11+
const pushable = require('pull-pushable')
1112
const toStream = require('pull-stream-to-stream')
1213
const toPull = require('stream-to-pull-stream')
1314
const CID = require('cids')
1415
const waterfall = require('async/waterfall')
1516
const isStream = require('isstream')
17+
const Duplex = require('stream').Duplex
1618

1719
module.exports = function files (self) {
1820
const createAddPullStream = (options) => {
@@ -30,7 +32,19 @@ module.exports = function files (self) {
3032
callback = options
3133
options = undefined
3234
}
33-
callback(null, toStream(createAddPullStream(options)))
35+
36+
const addPullStream = createAddPullStream(options)
37+
const p = pushable()
38+
const s = pull(
39+
p,
40+
addPullStream
41+
)
42+
43+
const retStream = new AddStreamDuplex(s, p)
44+
45+
retStream.once('finish', () => p.end())
46+
47+
callback(null, retStream)
3448
},
3549

3650
createAddPullStream: createAddPullStream,
@@ -164,3 +178,28 @@ function normalizeContent (content) {
164178
}
165179

166180
function noop () {}
181+
182+
class AddStreamDuplex extends Duplex {
183+
constructor (pullStream, push, options) {
184+
super(Object.assign({ objectMode: true }, options))
185+
this._pullStream = pullStream
186+
this._pushable = push
187+
}
188+
189+
_read () {
190+
this._pullStream(null, (end, data) => {
191+
if (end) {
192+
if (end instanceof Error) {
193+
this.emit('error', end)
194+
}
195+
} else {
196+
this.push(data)
197+
}
198+
})
199+
}
200+
201+
_write (chunk, encoding, callback) {
202+
this._pushable.push(chunk)
203+
callback()
204+
}
205+
}

0 commit comments

Comments
 (0)