Skip to content

Commit

Permalink
Improve AIFF parser read loop, prevent throwing EOF exception.
Browse files Browse the repository at this point in the history
  • Loading branch information
Borewit committed Oct 20, 2020
1 parent 04aa169 commit f661391
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/aiff/AiffParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ export class AIFFParser extends BasicParser {
this.metadata.setFormat('lossless', !this.isCompressed);

try {
do {
while (!this.tokenizer.fileInfo.size || this.tokenizer.fileInfo.size - this.tokenizer.position >= iff.Header.len) {
debug('Reading AIFF chunk at offset=' + this.tokenizer.position);
const chunkHeader = await this.tokenizer.readToken<iff.IChunkHeader>(iff.Header);

debug(`Chunk id=${chunkHeader.chunkID}`);
const nextChunk = 2 * Math.round(chunkHeader.chunkSize / 2);
const bytesRead = await this.readData(chunkHeader);
await this.tokenizer.ignore(nextChunk - bytesRead);
} while (true);
}
} catch (err) {
if (err instanceof strtok3.EndOfStreamError) {
debug(`End-of-stream`);
Expand Down

0 comments on commit f661391

Please sign in to comment.