1.0.4 • Published 6 years ago
simple-message-reader v1.0.4
Simple message reader
Convert
ArrayBuffer
orBlob
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.
npm i simple-message-reader
Pull from CDN
<script src="https://unpkg.com/simple-message-reader"></script>
import { isBlob, isArrayBuffer, parseBlob, parseArrayBuffer } from 'simple-message-reader'
// from CDN
const simpleMessageReader = window.simpleMessageReader
API
Constants
Functions
acceptedTypesMap : Object
List of output formats accepted when parsing blobs
Kind: global constant
Attribute: acceptedTypesMap
Example
['arrayBuffer', 'binaryString', 'dataURL', 'text']
isBlob(input) ⇒ Boolean
Returns a boolean telling if value is blob or not
Kind: global function
Param | Type |
---|---|
input | Blob |
Example
isBlob(new Blob())
isArrayBuffer(input) ⇒ Boolean
Returns a boolean telling if value is any of the ArrayBuffer view or not
Kind: global function
Param | Type |
---|---|
input | ArrayBufferView |
Example
isArrayBuffer(new Uint8Array())
parseBlob(input, cb, outputFormat) ⇒ void
Parses 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.
Kind: global function
Param | Type | Default |
---|---|---|
input | Blob | |
cb | function | |
outputFormat | String | 'arrayBuffer' |
Example
parseBlob(new Blob(), function (error, output) {
}, 'arrayBuffer')
parseArrayBuffer(input) ⇒ String
Parses the arrayBuffer to a string
Kind: global function
Param | Type |
---|---|
input | ArrayBufferView |
Example
parseArrayBuffer(new Uint8Array([72, 101, 108, 108, 111, 32, 33])