Created
October 12, 2017 15:40
-
-
Save fntneves/7b5c8c512a0a86034673009744a7b1b3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default class FileReaderPromise { | |
constructor(file) { | |
this.file = file; | |
} | |
readAsText() { | |
return new Promise((resolve, reject) => { | |
const reader = new FileReader(); | |
reader.onload = e => resolve(e.target.result); | |
reader.onerror = e => reject(new Error(`Error reading ${this.file.name}: ${e.target.result}`)); | |
reader.readAsText(this.file); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment