Skip to content

Instantly share code, notes, and snippets.

@nelsonfncosta
Created March 23, 2021 19:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nelsonfncosta/d47038a34ef8d8c4f06e8386806cfd40 to your computer and use it in GitHub Desktop.
Save nelsonfncosta/d47038a34ef8d8c4f06e8386806cfd40 to your computer and use it in GitHub Desktop.
READ FILE snippet
function readFile(file: File | null) {
const reader = new FileReader();
reader.addEventListener("load", (event) => {
const result = event.target.result;
console.log(result);
});
reader.addEventListener("progress", (event) => {
if (event.loaded && event.total) {
const percent = (event.loaded / event.total) * 100;
console.log(`Progress: ${Math.round(percent)}`);
}
});
reader.readAsText(file);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment