files.ts 416 B

12345678910111213141516171819
  1. import * as TO from "fp-ts/TaskOption"
  2. export const readFileAsText = (file: File) =>
  3. TO.tryCatch(
  4. () =>
  5. new Promise<string>((resolve, reject) => {
  6. const reader = new FileReader()
  7. reader.onload = () => {
  8. resolve(reader.result as string)
  9. }
  10. reader.onerror = () => {
  11. reject(new Error("File err"))
  12. }
  13. reader.readAsText(file)
  14. })
  15. )