Line data Source code
1 : import { PlatformFile } from "./file.js";
2 :
3 1 : export class WebFile implements PlatformFile {
4 : /// The file name
5 1 : public readonly path: string;
6 : /// The file
7 1 : public readonly file: File;
8 :
9 : /// The constructor
10 1 : constructor(file: File, path: string) {
11 1 : this.path = path;
12 1 : this.file = file;
13 1 : }
14 : /// The file size in bytes
15 1 : get size(): number {
16 1 : return this.file.size;
17 1 : }
18 : /// The browser Blob backing the file
19 1 : get blob(): Blob {
20 1 : return this.file;
21 1 : }
22 : /// Open a stream for reading the file
23 0 : stream(): ReadableStream<Uint8Array> {
24 0 : return this.file.stream();
25 0 : }
26 : /// Read the file as array buffer
27 0 : async readAsArrayBuffer(): Promise<Uint8Array> {
28 0 : const fileBytes = await this.file.arrayBuffer();
29 0 : return new Uint8Array(fileBytes);
30 0 : }
31 1 : }
|