From a08e262dfc6449c231dbaab0302b1632489c3f09 Mon Sep 17 00:00:00 2001 From: Vanilagy <1696106+Vanilagy@users.noreply.github.com> Date: Tue, 11 Aug 2026 12:46:33 +0200 Subject: [PATCH] Work around WebKit not respecting TypedArray offets for FileSystemWritableFileStream data (fixes #459) --- src/target.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/target.ts b/src/target.ts index df961a9..4f78707 100644 --- a/src/target.ts +++ b/src/target.ts @@ -8,7 +8,7 @@ import type { FileHandle } from 'node:fs/promises'; import * as nodeAlias from './node'; -import { assert, EventEmitter, FilePath, MaybePromise } from './misc'; +import { assert, EventEmitter, FilePath, isWebKit, MaybePromise } from './misc'; const node = typeof nodeAlias !== 'undefined' ? nodeAlias // Aliasing it prevents some bundler warnings @@ -542,9 +542,19 @@ export class StreamTarget extends Target { throw new Error('Internal error: Monotonicity violation.'); } + const isPartialView = section.start !== 0 || section.end !== chunk.data.byteLength; + + let data: Uint8Array; + if (isPartialView && isWebKit()) { + // https://bugs.webkit.org/show_bug.cgi?id=302733 + data = chunk.data.slice(section.start, section.end); + } else { + data = chunk.data.subarray(section.start, section.end); + } + void this._streamWriter.write({ type: 'write', - data: chunk.data.subarray(section.start, section.end), + data, position, }).catch((error) => { this._writeError ??= error;