New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

base128

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

base128

Encode, decode binary to/from UTF-8 string using Base128.

latest
Source
npmnpm
Version
0.2.1
Version published
Maintainers
1
Created
Source

base128

In many protocols or formats like JSON or early WebSocket, it requires String in UTF-8 representation, so we can not store raw binary data into String without encoding like Base64.

However, Base64 encodes binary into only 6 bits space but we can actually use one more bit in valid UTF-8 string from U+0000 to U+007F, so using Base128 is better than Base64 (~ 16% more information we can store in the same space.)

This Base128 module provides simple encode, decode interfaces between Buffer and String on Node.js which are implemented in C++.

Usage

Use npm to grab a package then load by require().

$ npm install base128
$ node
> var base128 = require('base128')

Examples

To Encode,

 var base128 = require('base128')
 var binary = new Buffer([0xFF, 0x01])
 var string = base128.encode(binary)
 console.log(string) #=> '\u007F\u0003\u0000' (These cahracters are invisible, though.)

To Decode,

 var base128 = require('base128')
 var string = '\u007F\u0003\u0000'
 var binary = base128.decode(string)
 console.log(binary) #=> '<Buffer ff 01>'

Development

Base128 is using NAN to build native add-on binary for Node.js. npm install does everything for you, but there are extra scripts defined in package.json.

$ npm run clean # Cleanup build files
$ npm run distclean # Cleanup all generated files
$ npm run build # Build native add-on binary

To test Base128,

$ npm test

FAQs

Package last updated on 23 Dec 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts