Skip to content
This repository has been archived by the owner on Apr 20, 2018. It is now read-only.

Latest commit

 

History

History
54 lines (42 loc) · 2.25 KB

filereader.md

File metadata and controls

54 lines (42 loc) · 2.25 KB

Rx.DOM.fromReader(file, [progressObserver])

The FileReader object lets web applications asynchronously read the contents of files (or raw data buffers) stored on the user's computer, using File or Blob objects to specify the file or data to read as an observable sequence.

Arguments

  1. file (File | Blob): The file to read.
  2. [progressObserver] (Rx.Observer): An optional Observer to watch for progress events.

Returns

(Object): An object which has the following functions:

  • asArrayBuffer() - (Rx.Observable): This method is used to read the file as an ArrayBuffer as an Observable stream.
  • asBinaryString() - (Rx.Observable): This method is used to read the file as a binary data string as an Observable stream.
  • asDataURL() - (Rx.Observable): This method is used to read the file as a URL of the file's data as an Observable stream.
  • asText(encoding) - (Rx.Observable): This method is used to read the file as a string as an Observable stream.

Example

Read the contents of the file picker only if plain files:

Rx.DOM.change(filesInput)
  .flatMap(function (event) {
    return Rx.Observable.from(event.target.files);
  })
  .filter(function (file) {
    return file.type.match('plain');
  })
  .flatMap(function (file) {
    return Rx.DOM.fromReader(file).asText();
  })
  .subscribe(function (contents) {
    console.log(contents);
  });

Location

File:

Dist:

Prerequisites:

NPM Packages:

NuGet Packages:

Unit Tests: