chunked-buffer

Small function you can wrap fs.createReadStream with to get fixed size data chunks

Usage no npm install needed!

<script type="module">
  import chunkedBuffer from 'https://cdn.skypack.dev/chunked-buffer';
</script>

README

chunked-buffer

Downloads

Small function you can wrap fs.createReadStream with to get fixed size data chunks.

chunked-buffer modifies stream.Readable's 'data' event to make it so that chunks will have a fixed amount of bytes instead of getting randomly sized chunks. This can be extremely helpful if the target you pipe to expects a certain amount of bytes or if that target has a byte limitation (a udp packet for example).

Usage

const chunked = require('chunked-buffer')
const rs = chunked(fs.createReadStream('path/to/file'), { chunkSize: 20000 })

rs.on('data', (chunk) => {
  // chunk is a Buffer with a size of 20000 bytes.
})