https://github.com/dy/arraybuffer-to-string
Convert ArrayBuffer to string
https://github.com/dy/arraybuffer-to-string
Last synced: 8 months ago
JSON representation
Convert ArrayBuffer to string
- Host: GitHub
- URL: https://github.com/dy/arraybuffer-to-string
- Owner: dy
- Created: 2017-06-27T23:25:36.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2018-11-20T04:05:51.000Z (over 7 years ago)
- Last Synced: 2025-10-24T23:28:44.397Z (8 months ago)
- Language: JavaScript
- Size: 8.79 KB
- Stars: 24
- Watchers: 1
- Forks: 5
- Open Issues: 1
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# arraybuffer-to-string [](http://github.com/badges/stability-badges) [](https://travis-ci.org/dy/arraybuffer-to-string)
Convert _ArrayBuffer_ to string with optional encoding.
[](https://npmjs.org/package/arraybuffer-to-string/)
```js
var ab2str = require('arraybuffer-to-string')
var uint8 = new Uint8Array([ 72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100, 33 ])
ab2str(uint8) // 'Hello World!'
ab2str(uint8, 'base64') // 'SGVsbG8gV29ybGQh'
ab2str(uint8, 'hex') // '48656c6c6f20576f726c6421'
ab2str(uint8, 'iso-8859-2') // 'Hello World!'
```
### var str = arrayBufferToString(buffer, encoding='utf8')
Convert ArrayBuffer/ArrayBufferView/Array `buffer` to string with defined encoding. Available encoding: `utf8`, `binary`, `base64`, `hex`, `ascii`, `latin1`, `ucs2`, `utf16` and [many others](https://developer.mozilla.org/en-US/docs/Web/API/TextDecoder/encoding).
Note: in browser it relies on [TextDecoder API](https://developer.mozilla.org/en-US/docs/Web/API/TextDecoder/decode), so if you are dealing with charsets other than `utf8`, `ascii`, `binary` or `base64` in old browsers, please include [encoding polyfill](https://github.com/inexorabletash/text-encoding).
### Related
* [string-to-arraybuffer](https://github.com/dy/string-to-arraybuffer) − convert string to arraybuffer.
* [create-data-uri](https://www.npmjs.com/package/create-data-uri) − convert binary data to datauri string.