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