FileReader for most
npm install most-file-reader
import {readAsDataURL} from 'most-file-reader'
import {change} from '@most/dom-event'
import {from} from 'most'
const filesStream = change(document.body)
.chain(event => from(event.target.files).filter(file => file.type.match('image')))
readAsDataURL(filesStream)
.observe(console.info.bind(console))
or fluently with thru
import {readAsDataURL} from 'most-file-reader'
import {change} from '@most/dom-event'
import {from} from 'most'
change(document.body)
.chain(event => from(event.target.files).filter(file => file.type.match('image')))
.thru(readAsDataURL)
.observe(console.info.bind(console))
readAsDataURL
will output a ProgressEvent
which contains a base64 encoded url.
readAsArrayBuffer
will output a ProgressEvent
which contains a ArrayBuffer
of file data.
readAsText
will output a ProgressEvent
which contains a text string of the file contents.
fileReader
is the underlying method for the above functions.
import {fileReader} from 'most-file-reader'
import {change} from '@most/dom-event'
import {from} from 'most'
const fileStream = change(document.body)
.chain(event => from(event.target.files))
fileReader('readAsDataURL', fileStream)
.observe(console.info.bind(console))
- Add tests
- Publish to npm