Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/thlorenz/stringify-buffer

Converts a buffer a collection of strings, one for each possible encoding.
https://github.com/thlorenz/stringify-buffer

Last synced: 24 days ago
JSON representation

Converts a buffer a collection of strings, one for each possible encoding.

Awesome Lists containing this project

README

        

# stringify-buffer [![build status](https://secure.travis-ci.org/thlorenz/stringify-buffer.png)](http://travis-ci.org/thlorenz/stringify-buffer)

Converts a buffer a collection of strings, one for each possible encoding.

```js
const stringify = require('stringify-buffer')
const buf = Buffer.from('Hello ☃')
console.log(stringify(buf))
```

{ ascii: 'Hello b\u0018\u0003',
utf8: 'Hello ☃',
utf16le: '效汬飢',
binary: 'Hello ☃',
base64: 'SGVsbG8g4piD',
hex: '48656c6c6f20e29883' }

## Installation

npm install stringify-buffer

## [API](https://thlorenz.github.io/stringify-buffer)

### stringifyBuffer

Stringifies the given buffer once for each encoding and adds
the result a hash.

**Parameters**

- `buf` **[Buffer](https://nodejs.org/api/buffer.html)** the buffer to stringify
- `encodings` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)<[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)>?** the encodings to be used, if not supplied [all valid
encodings](https://nodejs.org/api/buffer.html#buffer_buffers_and_character_encodings) are used

Returns **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)<[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String), [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)>** a hash with a string value of the buffer for each of the supplied encodings

### stringifyBuffer.encodings

Returns an array of all valid Buffer encodings that are supported.
This is the same array that is used if no `encodings` is passed to @see stringifyBuffers.

Returns **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)<[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)>** all valid Buffer encodings

## License

MIT