mirror of
https://github.com/CharaChorder/DeviceManager.git
synced 2026-02-14 05:02:42 +00:00
feat: adjust chunking
This commit is contained in:
@@ -564,7 +564,6 @@ export class CharaDevice {
|
|||||||
|
|
||||||
const writer = this.port.writable!.getWriter();
|
const writer = this.port.writable!.getWriter();
|
||||||
try {
|
try {
|
||||||
const log: SerialLogEntry[] = [];
|
|
||||||
const start = performance.now();
|
const start = performance.now();
|
||||||
writer.write(new TextEncoder().encode(`RST OTA\r\n`));
|
writer.write(new TextEncoder().encode(`RST OTA\r\n`));
|
||||||
|
|
||||||
@@ -575,11 +574,11 @@ export class CharaDevice {
|
|||||||
const chunkSize = 128;
|
const chunkSize = 128;
|
||||||
const chunks: Promise<void>[] = [];
|
const chunks: Promise<void>[] = [];
|
||||||
for (let i = 0; i < file.byteLength; i += chunkSize) {
|
for (let i = 0; i < file.byteLength; i += chunkSize) {
|
||||||
const chunk = file.slice(i, i + chunkSize);
|
const size = Math.min(chunkSize, file.byteLength - i);
|
||||||
chunks.push(
|
chunks.push(
|
||||||
writer
|
writer
|
||||||
.write(new Uint8Array(chunk))
|
.write(new Uint8Array(file, i, size))
|
||||||
.then(() => progress(i + chunk.byteLength, file.byteLength)),
|
.then(() => progress(i + size, file.byteLength)),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
await Promise.all(chunks);
|
await Promise.all(chunks);
|
||||||
|
|||||||
Reference in New Issue
Block a user