str2buf
isomorphic string <=> buffer in 183 bytes
Last updated 7 years ago by kevlened .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install str2buf 
SYNC missed versions from official npm registry.

str2buf NPM Build

isomorphic string <=> buffer in 198 bytes

Install

npm install str2buf

Usage

You must provide strings where each character is represented by a single byte (also known as the binary string format). For example, the output of a atob operation or any ASCII string would be allowed.

const str2buf = require('str2buf')

str2buf.toUint8Array('hello')
// new Uint8Array([104,101,108,108,111])

str2buf.fromUint8Array(new Uint8Array([104,101,108,108,111]))
// 'hello'

str2buf.toBuffer('hello')
// ArrayBuffer

str2buf.fromBuffer(new Uint8Array([104,101,108,108,111]).buffer)
// 'hello'

Can it be smaller?

If you use ES6 imports with a bundler that supports tree-shaking, yes!

import { fromUint8Array } from 'str2buf'

Perf profile

⏱ browser performance on 1000 arrays or strings of size 25003:
str2buf.fromUint8Array: 245.842ms
str2buf.toUint8Array: 165.240ms
str2buf.fromBuffer: 234.920ms
str2buf.toBuffer: 160.021ms

⏱ node performance on 1000 arrays or strings of size 25003:
str2buf.fromUint8Array: 20.213ms
str2buf.toUint8Array: 15.655ms
str2buf.fromBuffer: 32.880ms
str2buf.toBuffer: 21.514ms

License

MIT

Current Tags

  • 1.3.0                                ...           latest (7 years ago)

7 Versions

  • 1.3.0                                ...           7 years ago
  • 1.2.2                                ...           7 years ago
  • 1.2.1                                ...           7 years ago
  • 1.2.0                                ...           7 years ago
  • 1.1.1                                ...           7 years ago
  • 1.1.0                                ...           7 years ago
  • 1.0.0                                ...           7 years ago
Maintainers (1)
Downloads
Total 1
Today 1
This Week 1
This Month 1
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (1)
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE