Convert ArrayBuffer and Blobs to strings. Browser only
npm install simple-message-readerArrayBuffer or Blob to string (Browser only)
The websocket or XHR requests now can return data as a Blob or ArrayBuffer. Using this package, you can conver them back to string.
``bash`
npm i simple-message-reader
Pull from CDN
`html`
`js
import { isBlob, isArrayBuffer, parseBlob, parseArrayBuffer } from 'simple-message-reader'
// from CDN
const simpleMessageReader = window.simpleMessageReader
`
ObjectList of output formats accepted when parsing
blobs
BooleanReturns a boolean telling if value is blob or
not
BooleanReturns a boolean telling if value is any of
the ArrayBuffer view or not
voidParses the blob to any of the accepted outputFormat types.
Callback will be called with error, if outputFormat is invalid
or input is not a blob.
StringParses the arrayBuffer to a string
ObjectKind: global constant
Attribute: acceptedTypesMap
Example
`js`
['arrayBuffer', 'binaryString', 'dataURL', 'text']
BooleanKind: global function
| Param | Type |
| --- | --- |
| input | Blob |
Example
`js`
isBlob(new Blob())
BooleanKind: global function
| Param | Type |
| --- | --- |
| input | ArrayBufferView |
Example
`js`
isArrayBuffer(new Uint8Array())
voidCallback will be called with error, if outputFormat is invalidinput
or is not a blob.
Kind: global function
| Param | Type | Default |
| --- | --- | --- |
| input | Blob | |
| cb | function | |
| [outputFormat] | String | 'arrayBuffer' |
Example
`js
parseBlob(new Blob(), function (error, output) {
StringKind: global function
| Param | Type |
| --- | --- |
| input | ArrayBufferView |
Example
`js``
parseArrayBuffer(new Uint8Array([72, 101, 108, 108, 111, 32, 33])