0.1.11 • Published 5 months ago

cwi-array-encoding v0.1.11

Weekly downloads
-
License
Open BSV License
Repository
github
Last release
5 months ago

cwi-array-encoding

Efficiently encode Uint8Arrays as base64 strings

Usage

import { encodeUint8AsString, decodeUint8FromString } from '@cwi/array-encoding'

// Start with a Uint8Array of any length
const originalArray = new Uint8Array([1, 2, 3, 4])

// encodeUint8ArrayAsString produces an efficiently-encoded base64 string
const encodedString = encodeUint8AsString(originalArray)

// To get your original array back, just pass the base64 string to decodeUint8FromString
const decodedArray = decodeUint8FromString(encodedString)

// You can also encode and decode hex strings by specifiying the format (defaults to base64)
const encodedStringAsHex = encodeUint8AsString(originalArray, 'hex')
const decodedArrayFromHex = decodeUint8FromString(encodedStringAsHex, 'hex')

API

encodeUint8AsString(Uint8Array, outputFormat) => string

This function takes an arbitrary Uint8Array of any length and returns an efficiently-encoded base64 or hex string that can be easily stored in a database or sent over the network.

decodeUint8FromString(string, format) => Uint8Array

This function takes a base64 or hex encoded string that was produced by the encodeUint8AsString function and returns the original Uint8Array.

Testing

If any changes are required to this library, please maintain an adequate level of test coverage for critical production environments.

License

The license for the code in this repository is the Open BSV License.

0.1.10

5 months ago

0.1.11

5 months ago

0.1.8

1 year ago

0.1.7

1 year ago

0.1.5

2 years ago