src/util/file-util.js
async function readBytes ({ file, start, chunkSize }) {
  const buffer = Buffer.alloc(chunkSize)

  const fileDescriptor = await fs.open(file, 'r')

  const { bytesRead } = await fs.read(
    fileDescriptor,
    buffer,          // buffer to write to
    0,               // offset in the buffer to start writing at
    chunkSize,       // number of bytes to read
    start            // where to begin reading from in the file
  )

  // Slice the buffer in case chunkSize > fileSize - start
  return buffer.slice(0, bytesRead)
}
async function readBytes ({ file, start, chunkSize }) {
  const buffer = Buffer.alloc(chunkSize)

  const fileDescriptor = await fs.open(file, 'r')

  const { bytesRead } = await fs.read(
    fileDescriptor,
    buffer,          // buffer to write to
    0,               // offset in the buffer to start writing at
    chunkSize,       // number of bytes to read
    start            // where to begin reading from in the file
  )

  // Slice the buffer in case chunkSize > fileSize - start
  return buffer.slice(0, bytesRead)
}
async function readBytes ( { file , start , chunkSize } ) { const buffer = Buffer . alloc ( chunkSize ) const fileDescriptor = await fs . open ( file , 'r' ) const { bytesRead } = await fs . read ( fileDescriptor , buffer , // buffer to write to 0 , // offset in the buffer to start writing at chunkSize , // number of bytes to read start // where to begin reading from in the file ) // Slice the buffer in case chunkSize > fileSize - start return buffer . slice ( 0 , bytesRead ) }
Read `chunkSize` bytes from the given `file`, starting from byte number `start`.

@param {string} file      - path to a file
@param {number} start     - byte to start reading from
@param {number} chunkSize - number of bytes to read
@returns {Promise<Buffer>}
Read chunkSize bytes from the given file starting from byte number start .