Skip to content

Commit 6f31e09

Browse files
committed
Fix bug when filed stream is manually read via events
1 parent 3ba3a64 commit 6f31e09

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

main.js

-2
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,6 @@ function File (options) {
163163
if (self.buffers.length > 0) {
164164
stream.Stream.prototype.pipe.call(self, fs.createWriteStream(self.path))
165165
} else if (self.listeners('data').length > 0) {
166-
fs.createReadStream(self.path).pipe(self.dest)
167-
} else {
168166
fs.createReadStream(self.path).pipe(self)
169167
}
170168
}

test/test.js

+21
Original file line numberDiff line numberDiff line change
@@ -207,4 +207,25 @@ function testhttp () {
207207
}
208208
testhttp()
209209

210+
function testManualRead () {
211+
var stream = filed(path.join(__dirname, 'fixture.txt'))
212+
213+
var expected =
214+
`abc
215+
xyz
216+
`
217+
var body = Buffer.from('')
218+
219+
stream.on('data', function (chunk) { body = Buffer.concat([body, chunk]) })
220+
stream.on('error', function (err) { throw err })
221+
stream.on('end', function () {
222+
var actual = body.toString('utf8')
223+
if ( actual !== expected ) {
224+
throw new Error(`Expected\n\n${actual}\n\nto equal\n\n${expected}`)
225+
}
226+
else console.log('Passed testManualRead')
227+
})
228+
}
229+
testManualRead()
230+
210231
process.on('exit', function () {console.log('All tests passed.')})

0 commit comments

Comments
 (0)