<script src="https://unpkg.com/promisify-file-reader"></script>
<script type="module">
import PromisifyFileReader from 'https://unpkg.com/promisify-file-reader?module'
</script>
dist/
├─ index.cjs ( CommonJS )
├─ index.js ( UMD )
├─ index.min.js ( UMD, compressed )
├─ index.mjs ( ES Module )
└─ index.min.mjs ( ES Module, compressed )
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)
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)
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
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'