Module: lib/png-chunks-extractor

Requires

Methods

(static) default(file, optionsopt) → {Promise.<{chunks: Array.<Chunk>, chunksByType: Array.<{type:number, chunks:Array.<Chunk>}>}>|null}

Parse a PNG file and return its data chunks

Parameters:
Name Type Attributes Description
file PathLike | FileHandle

PNG file

options Object <optional>

Parsing options

Properties
Name Type Attributes Default Description
validateStruct boolean <optional>
true

If truthy, validate the general PNG structure (file starts with PNG signature and chunk stream begins with an IHDR chunk and ends with an empty IEND chunk). Return null when validation fails

validateCrc boolean <optional>
false

If truthy, check crc signature of each chunk and ignore it if there is a mismatch, further mismatch behaviour depends on options.throwOnError and options.logOnError

throwOnError boolean <optional>
false

If truthy, throws error when validation fails

logOnError boolean <optional>
true

If truthy, logs if validation fails

Source:
Returns:

The raw chunks array (by order of appearance) and an object of these chunks indexed by chunk type (as a 32 bit unsigned int)

Type
Promise.<{chunks: Array.<Chunk>, chunksByType: Array.<{type:number, chunks:Array.<Chunk>}>}> | null

(inner) extractNextChunk(buffer, offset, parseCrcopt) → {Object.<{offset: number, crc: number, crcBuf: Buffer, chunk: Chunk}>}

Extract a chunk from a PNG buffer

Parameters:
Name Type Attributes Default Description
buffer Buffer

Raw PNG Buffer

offset number

Current read offset

parseCrc boolean <optional>
false

If truthy, crc of each chunk is parsed

Source:
Returns:

Parsed chunk, chunk's CRC and new offset

Type
Object.<{offset: number, crc: number, crcBuf: Buffer, chunk: Chunk}>