Content Encodings
Content encoding and decoding library for node applications. Accepts anything, outputs buffer.
Supported Encoding Types
- base64
- quoted-printable
- utf8
- ascii
- hex
- url
- gzip
- deflate
- brotli
- zstd
Install
npm install content-encodings
Usage
It's pretty straight-forward. The library has two method in its API. encode
and decode
.
.encode(type, data, ?options, ?callback)
Encodes the data
you sent according to the encoding type
with options
.
callback
is necessary for compressors (gzip
, deflate
, brotli
, zstd
).
// example hex encodingconst contentencodings = contentencodings// outputs: 6c6f72656d20697073756d
// example zstd encodingconst contentencodings = contentencodings
More examples can be found in the tests
folder.
.decode(type, data, ?options, ?callback)
Decodes the encoded data
you sent according to the encoding type
with options
.
callback
is necessary for compressors (gzip
, deflate
, brotli
, zstd
).
// example hex decodingconst contentencodings = // toString because of output is buffercontentencodings// outputs: lorem ipsum
// example zstd encodingconst contentencodings = contentencodings
More examples can be found in the tests
folder.