-
-
Notifications
You must be signed in to change notification settings - Fork 59
/
file.ts
45 lines (39 loc) · 1.4 KB
/
file.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
(globalThis => {
globalThis.File = class extends Blob {
readonly lastModified: number;
readonly name: string;
readonly webkitRelativePath: string;
constructor(fileBits: BlobPart[], fileName: string, options?: FilePropertyBag) {
super(fileBits, options);
this.lastModified = options?.lastModified || Date.now();
this.name = fileName;
this.webkitRelativePath = '';
}
};
// TODO: properly implement FileReader. It should extends Event
// @ts-expect-errore to fix
globalThis.FileReader = class {
// @ts-expect-errore to fix
readonly DONE: number;
// @ts-expect-errore to fix
readonly EMPTY: number;
// @ts-expect-errore to fix
readonly LOADING: number;
// eslint-disable-next-line @typescript-eslint/no-empty-function
constructor() {}
// @ts-expect-errore to fix
// eslint-disable-next-line @typescript-eslint/no-empty-function
onerror(): ((this: FileReader, ev: ProgressEvent<FileReader>) => any) | null {}
// @ts-expect-errore to fix
// eslint-disable-next-line @typescript-eslint/no-empty-function
onload(): ((this: FileReader, ev: ProgressEvent<FileReader>) => any) | null {}
readAsText(blob: Blob, encoding?: string) {
blob.text().then(text => {
// @ts-expect-errore to fix
this.result = text;
// @ts-expect-errore to fix
this.onload(this);
});
}
};
})(globalThis);