Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a way to purge temp buffer data #89

Merged
merged 3 commits into from
Dec 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "warcio",
"version": "2.4.2",
"version": "2.4.3",
"keywords": [
"WARC",
"web archiving"
Expand Down
5 changes: 5 additions & 0 deletions src/lib/warcserializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export type WARCSerializerOpts = {
export abstract class BaseSerializerBuffer {
abstract write(chunk: Uint8Array): void;
abstract readAll(): AsyncIterable<Uint8Array>;
abstract purge(): void;
}

// ===========================================================================
Expand All @@ -42,6 +43,10 @@ export class SerializerInMemBuffer extends BaseSerializerBuffer {
yield buff;
}
}

purge() {
this.buffers = [];
}
}

// ===========================================================================
Expand Down
9 changes: 8 additions & 1 deletion src/node/warcserializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,14 @@ export class TempFileBuffer extends warcserializer.SerializerInMemBuffer {
yield buff;
}

await unlink(this.filename);
await this.purge();
}

override async purge() {
if (this.filename) {
await unlink(this.filename);
this.filename = "";
}
}
}

Expand Down
Loading