promisify-file-reader
v4.1.0
Published
Promise File Reader
Downloads
189
Readme
Promisify File Reader
Usage
<script src="https://unpkg.com/promisify-file-reader"></script>
<script type="module">
import PromisifyFileReader from 'https://unpkg.com/promisify-file-reader?module'
</script>
Files
dist/
├─ index.cjs ( CommonJS )
├─ index.js ( UMD )
├─ index.min.js ( UMD, compressed )
├─ index.mjs ( ES Module )
└─ index.min.mjs ( ES Module, compressed )
API
Prototype
supported all FileReader
methods:
readAsArrayBuffer
readAsBinaryString
readAsDataURL
readAsText
FileReader#readAsBinaryString
is not available in some browser, like IE 10we use arrayBuffer to binaryString to support this method
example:
const fileReader = new PromisifyFileReader()
const result = await fileReader.readAsArrayBuffer(file)
Static methods
in fact new PromisifyFileReader()
is not really required, all methods can use as static
readAsArrayBuffer
readAsBinaryString
readAsDataURL
readAsText
example:
const result = await PromisifyFileReader.readAsArrayBuffer(file)
Shortcuts
you can also strip the readAs
prefix
arrayBuffer
binaryString
dataURL
text
Notice: shortcuts are NOT available in prototype
example:
const result = await PromisifyFileReader.arrayBuffer(file)
// => same as readAsArrayBuffer
ES Module
the ES Module build exports
{
// default
PromisifyFileReader as default,
// named
arrayBuffer,
binaryString,
dataURL,
text,
readAsArrayBuffer,
readAsBinaryString,
readAsDataURL,
readAsText,
}
import example:
// import default
import PromisifyFileReader from 'promisify-file-reader'
// import named
import {
arrayBuffer,
// ...
} from 'promisify-file-reader'
// import both
import PromisifyFileReader, {
arrayBuffer,
// ...
} from 'promisify-file-reader'