Skip to content

Commit

Permalink
FS/AppFS: improve chunk handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Pwuts committed Apr 6, 2023
1 parent 3f0a52c commit 4f2f07d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
9 changes: 5 additions & 4 deletions src/api/appfs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,14 @@ export class BadgeAppFSApi {
throw new Error(`Failed to open app file '${name}'`);
}

let chunkSize = new ArrayBuffer(4);
new DataView(chunkSize).setUint32(0, 64, true);
const chunkSize = 64;
let chunkSizeField = new ArrayBuffer(4);
new DataView(chunkSizeField).setUint32(0, chunkSize, true);

let parts = [];
while (true) {
let part = await this.transaction(BadgeUSB.PROTOCOL_COMMAND_TRANSFER_CHUNK, chunkSize, 4000);
if (part === null || part.byteLength < 1) break;
let part = await this.transaction(BadgeUSB.PROTOCOL_COMMAND_TRANSFER_CHUNK, chunkSizeField, 4000);
if (part === null || part.byteLength < chunkSize) break;
parts.push(part);
}
await this.fs.closeFile(); // This also works on appfs "files"
Expand Down
9 changes: 5 additions & 4 deletions src/api/filesystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,14 @@ export class BadgeFileSystemApi {
throw new Error(`Failed to open file '${filePath}'`);
}

let chunkSize = new ArrayBuffer(4);
new DataView(chunkSize).setUint32(0, 512, true);
const chunkSize = 512;
let chunkSizeField = new ArrayBuffer(4);
new DataView(chunkSizeField).setUint32(0, chunkSize, true);

let parts = [];
while (true) {
let part = await this.transaction(BadgeUSB.PROTOCOL_COMMAND_TRANSFER_CHUNK, chunkSize, 4000);
if (part === null || part.byteLength < 1) break;
let part = await this.transaction(BadgeUSB.PROTOCOL_COMMAND_TRANSFER_CHUNK, chunkSizeField, 4000);
if (part === null || part.byteLength < chunkSize) break;
parts.push(part);
}
await this.closeFile();
Expand Down
1 change: 0 additions & 1 deletion src/badge-usb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,6 @@ export class BadgeUSB {
} catch (error) {
if (!(error instanceof TimeoutError)) throw error;
}
console.debug(error);
if (payload) console.debug(`payload for failed ${commandCode}:`, payload, BadgeUSB.textDecoder.decode(payload));

delete this.pendingTransactions[transactionID];
Expand Down

0 comments on commit 4f2f07d

Please sign in to comment.