Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: empty streams #23

Merged
merged 3 commits into from
May 3, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ sudo: false
language: node_js
node_js:
- 8
- stable
- 10

# Make sure we have new NPM and yarn
before_install:
Expand Down
4 changes: 0 additions & 4 deletions src/decode.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,6 @@ function readVarintMessage (reader, maxLength, cb) {
return cb(new Error('size longer than max permitted length of ' + maxLength + '!'))
}

if (msgSize <= 0) {
return cb(true) // eslint-disable-line standard/no-callback-literal
}

readMessage(reader, msgSize, (err, msg) => {
if (err) {
return cb(err)
Expand Down
5 changes: 2 additions & 3 deletions test/fromReader.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,8 @@ describe('pull-length-prefixed decodeFromReader', () => {

// decode from reader
lp.decodeFromReader(reader, function (err, output) {
expect(err).to.be.instanceof(Error)
expect(output).to.equal(undefined)
done()
expect(output).to.eql(Buffer.alloc(0))
done(err)
jacobheun marked this conversation as resolved.
Show resolved Hide resolved
})
})
})
10 changes: 8 additions & 2 deletions test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,21 @@ describe('pull-length-prefixed', () => {
).to.be.eql([Buffer.alloc(1, 0)])
jacobheun marked this conversation as resolved.
Show resolved Hide resolved

pull(
pull.values(),
pull.values([
Buffer.alloc(0),
Buffer.from('more data')
]),
lp.encode(),
lp.decode(),
pull.collect((err, decoded) => {
if (err) throw err

expect(
decoded
).to.be.eql([])
).to.be.eql([
Buffer.alloc(0),
Buffer.from('more data')
])
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes sense, we should be able to pull an empty buffer.


done()
})
Expand Down