Skip to content

Instantly share code, notes, and snippets.

View ranouf's full-sized avatar

Cedric ranouf

View GitHub Profile
@iansinnott
iansinnott / rx-file-reader.js
Created June 5, 2017 19:36
A simple Rx abstraction over the FileReader API
/**
* Read the text contents of a File or Blob using the FileReader interface.
* This is an async interface so it makes sense to handle it with Rx.
* @param {blob} File | Blob
* @return Observable<string>
*/
const readFile = (blob) => Observable.create(obs => {
if (!(blob instanceof Blob)) {
obs.error(new Error('`blob` must be an instance of File or Blob.'));
return;