(
path: string,
stream: ReadableStream<Uint8Array>,
mimeType = "application/octet-stream"
)
| 905 | } |
| 906 | |
| 907 | async writeFileStream( |
| 908 | path: string, |
| 909 | stream: ReadableStream<Uint8Array>, |
| 910 | mimeType = "application/octet-stream" |
| 911 | ): Promise<void> { |
| 912 | const reader = stream.getReader(); |
| 913 | const chunks: Uint8Array[] = []; |
| 914 | let totalSize = 0; |
| 915 | for (;;) { |
| 916 | const { done, value } = await reader.read(); |
| 917 | if (done) break; |
| 918 | totalSize += value.byteLength; |
| 919 | if (totalSize > MAX_STREAM_SIZE) { |
| 920 | reader.cancel(); |
| 921 | throw new Error( |
| 922 | `EFBIG: stream exceeds maximum size of ${MAX_STREAM_SIZE} bytes` |
| 923 | ); |
| 924 | } |
| 925 | chunks.push(value); |
| 926 | } |
| 927 | |
| 928 | const buffer = new Uint8Array(totalSize); |
| 929 | let offset = 0; |
| 930 | for (const chunk of chunks) { |
| 931 | buffer.set(chunk, offset); |
| 932 | offset += chunk.byteLength; |
| 933 | } |
| 934 | |
| 935 | await this.writeFileBytes(path, buffer, mimeType); |
| 936 | } |
| 937 | |
| 938 | async appendFile( |
| 939 | path: string, |
no test coverage detected