Skip to content

Commit 44f9a80

Browse files
committed
fix(harmony): write patch buffers as ArrayBuffer
1 parent 311cefd commit 44f9a80

1 file changed

Lines changed: 18 additions & 3 deletions

File tree

harmony/pushy/src/main/ets/DownloadTask.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,17 @@ export function parseManifestToArrays(
5151
};
5252
}
5353

54+
function toArrayBufferSlice(
55+
payload: Uint8Array,
56+
offset: number,
57+
length: number,
58+
): ArrayBuffer {
59+
return payload.buffer.slice(
60+
payload.byteOffset + offset,
61+
payload.byteOffset + offset + length,
62+
);
63+
}
64+
5465
const DIFF_MANIFEST_ENTRY = '__diff.json';
5566
const HARMONY_BUNDLE_PATCH_ENTRY = 'bundle.harmony.js.patch';
5667
const TEMP_ORIGIN_BUNDLE_ENTRY = '.origin.bundle.harmony.js';
@@ -172,9 +183,13 @@ export class DownloadTask {
172183
let bytesWritten = 0;
173184

174185
while (bytesWritten < payload.byteLength) {
175-
const chunk = payload.subarray(bytesWritten, bytesWritten + chunkSize);
186+
const chunkLength = Math.min(
187+
chunkSize,
188+
payload.byteLength - bytesWritten,
189+
);
190+
const chunk = toArrayBufferSlice(payload, bytesWritten, chunkLength);
176191
await fileIo.write(writer.fd, chunk);
177-
bytesWritten += chunk.byteLength;
192+
bytesWritten += chunkLength;
178193
}
179194
} finally {
180195
if (writer) {
@@ -268,7 +283,7 @@ export class DownloadTask {
268283
break;
269284
}
270285

271-
await fileIo.write(writer.fd, new Uint8Array(buffer, 0, readLength));
286+
await fileIo.write(writer.fd, buffer.slice(0, readLength));
272287
offset += readLength;
273288

274289
if (readLength < FILE_COPY_BUFFER_SIZE) {

0 commit comments

Comments
 (0)