async getChunkAsBuffer()

in src/io/directory.ts [104:124]


  async getChunkAsBuffer(_path: string, chunkLength: number): Promise<Buffer> {
    const filePath = await this.getPath(_path);

    return new Promise((resolve, reject) => {
      const readStream = createReadStream(filePath, {
        flags: 'r',
        // This is important because you don't want to encode the bytes if you
        // are doing a binary check.
        encoding: '' as BufferEncoding,
        autoClose: true,
      });

      readStream.on('error', reject);

      readStream.pipe(
        new FirstChunkStream({ chunkLength }, (_, enc) => {
          resolve(enc);
        }),
      );
    });
  }