buffer-json-encoding
DefinitelyTyped icon, indicating that this package has TypeScript declarations provided by the separate @types/buffer-json-encoding package

1.0.2 • Public • Published

buffer-json-encoding

abstract-encoding

An abstract-encoding compatible JSON encoder/decoder that properly encodes/decodes buffers.

The reason this module exists is that JSON does not have a built-in data type for binary data, so Node.js by default encodes a buffer as an object of shape { type: "Buffer", data: [...] }. The issue is that Node.js does not decode these objects as Buffer instances, which is not very useful if you actually want to do something with them.

This module depends on buffer-json which provides a replacer & reviver for use with JSON.stringify & JSON.parse respectively. Buffer data is encoded as a base64-encoded string, rather than as an array of numbers. Buffers are decoded as expected with both (base-64 & array) encodings.

API

buffer = encode(obj, [buffer], [offset])
obj = decode(buf, [start], [end])
number = encodingLength(obj)

See abstract-encoding for more details.

Package Sidebar

Install

npm i buffer-json-encoding

Weekly Downloads

1,695

Version

1.0.2

License

ISC

Unpacked Size

6.34 kB

Total Files

4

Last publish

Collaborators

  • lachenmayer