Files
hoppscotch/packages/hoppscotch-common/src/helpers/functional/files.ts
2022-12-02 03:05:35 -05:00

20 lines
416 B
TypeScript

import * as TO from "fp-ts/TaskOption"
export const readFileAsText = (file: File) =>
TO.tryCatch(
() =>
new Promise<string>((resolve, reject) => {
const reader = new FileReader()
reader.onload = () => {
resolve(reader.result as string)
}
reader.onerror = () => {
reject(new Error("File err"))
}
reader.readAsText(file)
})
)