|
1 | 1 | /* global ReadableStream, WritableStream, Blob */ |
| 2 | +import { isBufferLike, toBuffer, splitBuffer } from '../util.js' |
2 | 3 | import { DEFAULT_STREAM_HIGH_WATER_MARK } from './stream.js' |
3 | | -import { isBufferLike, toBuffer } from '../util.js' |
4 | 4 | import { NotAllowedError } from '../errors.js' |
5 | 5 | import { readFileSync } from './index.js' |
6 | 6 | import mime from '../mime.js' |
@@ -282,7 +282,7 @@ export async function createFileSystemWritableFileStream (handle, options) { |
282 | 282 |
|
283 | 283 | const file = await handle.getFile() |
284 | 284 | let offset = 0 |
285 | | - let fd = null |
| 285 | + let fd = file?.[kFileDescriptor] || null |
286 | 286 |
|
287 | 287 | if (options?.keepExistingData === true) { |
288 | 288 | try { |
@@ -350,7 +350,12 @@ export async function createFileSystemWritableFileStream (handle, options) { |
350 | 350 | } |
351 | 351 |
|
352 | 352 | const buffer = toBuffer(data) |
353 | | - await fd.write(buffer, 0, buffer.byteLength, offset) |
| 353 | + const buffers = splitBuffer(buffer, 16 * 1024) |
| 354 | + while (buffers.length) { |
| 355 | + const buffer = buffers.shift() |
| 356 | + await fd.write(buffer, 0, buffer.byteLength, offset) |
| 357 | + offset += buffer.byteLength |
| 358 | + } |
354 | 359 | } |
355 | 360 | } |
356 | 361 |
|
@@ -384,7 +389,7 @@ export async function createFileSystemFileHandle (file, options = null) { |
384 | 389 | return path.basename(file) |
385 | 390 | } |
386 | 391 |
|
387 | | - return file.name |
| 392 | + return file?.name ?? '' |
388 | 393 | } |
389 | 394 |
|
390 | 395 | get kind () { |
|
0 commit comments