Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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);
}
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;
}