Skip to content

Commit

Permalink
Draft: Add Z1013 decoder (2)
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanschramm committed Nov 12, 2023
1 parent 176fb85 commit 9fa96c5
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions retroload-lib/src/decoding/writer/z1013/Z1013BlockProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,12 @@ export class Z1013BlockProcessor {
if (this.belongsToCurrentFile(bdr)) {
this.blocks.push(bdr);
} else {
yield new FileDecodingResult(
this.blocks.map((b) => b.data),
this.currentFileWasSuccessful() ? FileDecodingResultStatus.Success : FileDecodingResultStatus.Error,
this.blocks[0].blockBegin,
this.blocks[this.blocks.length - 1].blockEnd,
);
this.blocks = [];
yield this.finishFile();
}
}
if (this.blocks.length !== 0) {
yield this.finishFile();
}
}

private belongsToCurrentFile(bdr: BlockDecodingResult): boolean {
Expand All @@ -49,6 +46,18 @@ export class Z1013BlockProcessor {

return true;
}

private finishFile(): FileDecodingResult {
const fdr = new FileDecodingResult(
this.blocks.map((b) => b.data),
this.currentFileWasSuccessful() ? FileDecodingResultStatus.Success : FileDecodingResultStatus.Error,
this.blocks[0].blockBegin,
this.blocks[this.blocks.length - 1].blockEnd,
);
this.blocks = [];

return fdr;
}
}

export class FileDecodingResult {
Expand Down

0 comments on commit 9fa96c5

Please sign in to comment.