1.0.4 • Published 6 years ago

simple-message-reader v1.0.4

Weekly downloads
80
License
MIT
Repository
github
Last release
6 years ago

Simple message reader

Convert ArrayBuffer or Blob to string (Browser only)

Travis

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

ParamType
inputBlob

Example

isBlob(new Blob())

isArrayBuffer(input) ⇒ Boolean

Returns a boolean telling if value is any of the ArrayBuffer view or not

Kind: global function

ParamType
inputArrayBufferView

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

ParamTypeDefault
inputBlob
cbfunction
outputFormatString'arrayBuffer'

Example

parseBlob(new Blob(), function (error, output) {

}, 'arrayBuffer')

parseArrayBuffer(input) ⇒ String

Parses the arrayBuffer to a string

Kind: global function

ParamType
inputArrayBufferView

Example

parseArrayBuffer(new Uint8Array([72, 101, 108, 108, 111, 32, 33])