Files
xen-orchestra/@vates/read-chunk/.USAGE.md
2022-06-13 12:01:02 +02:00

705 B

readChunk(stream, [size])

  • returns the next available chunk of data
  • like stream.read(), a number of bytes can be specified
  • returns with less data than expected if stream has ended
  • returns null if the stream has ended and no data has been read
import { readChunk } from '@vates/read-chunk'
;(async () => {
  let chunk
  while ((chunk = await readChunk(stream, 1024)) !== null) {
    // do something with chunk
  }
})()

readChunkStrict(stream, [size])

Similar behavior to readChunk but throws if the stream ended before the requested data could be read.

import { readChunkStrict } from '@vates/read-chunk'

const chunk = await readChunkStrict(stream, 1024)