fix(read-chunk): handle already ended stream
This commit is contained in:
parent
13f19de1a0
commit
e2521b6688
@ -1,7 +1,9 @@
|
||||
'use strict'
|
||||
|
||||
const readChunk = (stream, size) =>
|
||||
size === 0
|
||||
stream.closed || stream.readableEnded
|
||||
? Promise.resolve(null)
|
||||
: size === 0
|
||||
? Promise.resolve(Buffer.alloc(0))
|
||||
: new Promise((resolve, reject) => {
|
||||
function onEnd() {
|
||||
|
@ -14,6 +14,13 @@ describe('readChunk', () => {
|
||||
expect(await readChunk(makeStream([]))).toBe(null)
|
||||
})
|
||||
|
||||
it('returns null if the stream is already ended', async () => {
|
||||
const stream = await makeStream([])
|
||||
await readChunk(stream)
|
||||
|
||||
expect(await readChunk(stream)).toBe(null)
|
||||
})
|
||||
|
||||
describe('with binary stream', () => {
|
||||
it('returns the first chunk of data', async () => {
|
||||
expect(await readChunk(makeStream(['foo', 'bar']))).toEqual(Buffer.from('foo'))
|
||||
|
@ -23,6 +23,7 @@
|
||||
|
||||
<!--packages-start-->
|
||||
|
||||
- @vates/read-chunk patch
|
||||
- xo-remote-parser patch
|
||||
- xo-server-transport-nagios patch
|
||||
- xo-web patch
|
||||
|
Loading…
Reference in New Issue
Block a user