[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

mostjs-community/most-file-reader

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

most-file-reader

FileReader for most

Install

npm install most-file-reader

API

readAsDataURL :: Stream File → Stream Event

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 :: Stream File → Stream Event

readAsArrayBuffer will output a ProgressEvent which contains a ArrayBuffer of file data.

readAsText :: Stream File → Stream Event

readAsText will output a ProgressEvent which contains a text string of the file contents.

fileReader :: String → Stream File → Stream Event

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))

Todo

  • Add tests
  • Publish to npm

Made with

@most/package-starter