decode binary streams into PNG chunk objects and back into binary
var rice = require'./index'decoder = ricedecodeencoder = riceencode// read a PNG and output a new PNG with metadatafscreateReadStream'in.png'pipedecoderon'data'ifchunktype !== 'IEND'return// emit a "tEXt" chunk containing metadata// before IENDdecoderemit'data' ricetext'key' JSONstringify'hello': 'world'pipeencoderpipefscreateWriteStream'out.png'
chunky-rice is a module that provides a decoder that takes
binary data and outputs
Chunk objects (allowing you to manipulate
a PNG on the fly); as well as a encoder that takes these
and turns them back into a binary stream.
Both the encoder and decoder are through streams.
chunky-rice provides porcelin methods for generating your own chunks,
and also, loves you unconditionally.
$ npm install chunky-rice
Creates a binary-to-Chunk through stream. Pausable and resumable.
Creates a Chunk-to-binary through stream. Pausable and resumable.
Creates a Chunk of the provided type with the provided data. CRC and length data is
not necessary --
data should only contain the chunk data!
Creates a tEXt chunk with a key of
and a value of
Returns the string representation of the chunk type.
If the chunk is a
tEXt chunk, returns the key data.
If the chunk is a
tEXt chunk, returns the value data.
Cached. If not pre-computed, recomputes the CRC of the provided data and type and writes it to the Chunk's backing store.
Cached. Returns the buffer representing the full data of the chunk (to include the 4 byte length, 4 byte type, data segment, and 4 byte CRC).
Modify an in-flight chunk -- only available on chunks sent via decoder
decoder.pause() on its source stream, and
the ready callback has been called.
fscreateReadStream'thing.png'pipericedecoderon'data'ifchunktype !== 'tEXt'returnchunkmodifysetTimeoutreadynull "hello\x00world"100pipericeencoderpipefscreateWriteStream'thing_out.png'