buffer up earlier so that written chunks become larger

This commit is contained in:
Simon Knott 2024-12-12 12:17:17 +01:00
parent df3f1b965a
commit 001c917819
No known key found for this signature in database
GPG key ID: 8CEDC00028084AEC

View file

@ -97,14 +97,14 @@ export class TarExtractor extends Writable {
}
override _write(chunk: Buffer, _encoding: string, callback: (err?: Error) => void) {
this.buffer = Buffer.concat([this.buffer, chunk]);
// we queue parsing because some operations need to be sequential,
// e.g. a directory entry needs to be created on disk
// before we can create the file entry in that directory.
this.queue = this.queue.then(() => this._writeImpl(chunk)).then(callback).catch(callback);
this.queue = this.queue.then(() => this._parse()).then(callback).catch(callback);
}
private async _writeImpl(chunk: Buffer): Promise<undefined> {
this.buffer = Buffer.concat([this.buffer, chunk]);
private async _parse(): Promise<undefined> {
while (this.buffer.length >= 512) {
if (!this.currentEntry) {
// two consecutive zero blocks mark end of archive, skip them