png-chunks-extractor is a Node.js module. It is available as a npm package.
npm i png-chunks-extractor
The package supports both ESM import and CJS require.
import chunksExtractor from 'png-chunks-extractor';
const {chunks, chunksByType} = await chunksExtractor('path/to/file');
chunks
is an array of PNG chunks data and type.
{
dataBuf: <Buffer 00 00 03 00 00 00 03 00 08 02 00 00 00>,
type: 1229472850 // 'IHDR' decimal value
}
-
PNGFile
<string> | <FileHandle> The file to parse. -
options
<Object>-
validateStruct
<boolean> Enables PNG structure validation. Default:true
-
validateCrc
<boolean> Enables Chunks CRC validation. CRC validation impacts parsing time. Default:false
-
throwOnError
<boolean> Throws an error whenever there is a validation error. Default:false
-
logOnError
<boolean> Logs any validation error. Default:true
-
- Returns <Object> | <null> If the general structure validation fails
-
chunks
<Object[]> An array of the PNG chunks.-
type
<uint 32> The latin1 decimal expression of the type -
dataBuf
<Buffer> Raw chunk data
-
-
chunksByType
<Object> An object with PNG type keys and chunk objects values
-
Parses PNGFile
and returns its chunks