How to use iobuffer - 2 common examples

To help you get started, we’ve selected a few iobuffer examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github image-js / fast-png / src / PNGEncoder.ts View on Github external
private encodeData(): void {
    const { width, height, channels, depth, data } = this._png;
    const slotsPerLine = channels * width;
    const newData = new IOBuffer().setBigEndian();
    let offset = 0;
    for (let i = 0; i < height; i++) {
      newData.writeByte(0); // no filter
      /* istanbul ignore else */
      if (depth === 8) {
        offset = writeDataBytes(data, newData, slotsPerLine, offset);
      } else if (depth === 16) {
        offset = writeDataUint16(data, newData, slotsPerLine, offset);
      } else {
        throw new Error('unreachable');
      }
    }
    const buffer = newData.toArray();
    const compressed = deflate(buffer, this._zlibOptions);
    this.encodeIDAT(compressed);
  }
github cheminfo / netcdfjs / src / index.js View on Github external
constructor(data) {
    const buffer = new IOBuffer(data);
    buffer.setBigEndian();

    // Validate that it's a NetCDF file
    utils.notNetcdf(buffer.readChars(3) !== 'CDF', 'should start with CDF');

    // Check the NetCDF format
    const version = buffer.readByte();
    utils.notNetcdf(version > 2, 'unknown version');

    // Read the header
    this.header = readHeader(buffer, version);
    this.buffer = buffer;
  }

iobuffer

Read and write binary data on ArrayBuffers

MIT
Latest version published 2 years ago

Package Health Score

51 / 100
Full package analysis

Popular iobuffer functions

Similar packages