fix: unclosed file
This commit is contained in:
parent
589a9acd3c
commit
1f79f36dfc
1 changed files with 12 additions and 2 deletions
|
@ -1,6 +1,6 @@
|
||||||
import { type FileHandle, open } from "node:fs/promises";
|
import { type FileHandle, open } from "node:fs/promises";
|
||||||
import { orderBy } from "natural-orderby";
|
import { orderBy } from "natural-orderby";
|
||||||
import { ZipReader, Reader, type Entry } from "@zip.js/zip.js";
|
import { ZipReader, Reader, type Entry, ZipReaderConstructorOptions } from "@zip.js/zip.js";
|
||||||
import EventEmitter from "node:events";
|
import EventEmitter from "node:events";
|
||||||
|
|
||||||
class FileReader extends Reader<string> {
|
class FileReader extends Reader<string> {
|
||||||
|
@ -55,10 +55,20 @@ class FileReader extends Reader<string> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class FileZipReader extends ZipReader<FileHandle> {
|
||||||
|
constructor(private reader: FileReader, options?: ZipReaderConstructorOptions) {
|
||||||
|
super(reader, options);
|
||||||
|
}
|
||||||
|
override async close(): Promise<void> {
|
||||||
|
super.close();
|
||||||
|
await this.reader.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export async function readZip(path: string): Promise<{
|
export async function readZip(path: string): Promise<{
|
||||||
reader: ZipReader<FileHandle>
|
reader: ZipReader<FileHandle>
|
||||||
}> {
|
}> {
|
||||||
const reader = new ZipReader(new FileReader(path), {
|
const reader = new FileZipReader(new FileReader(path), {
|
||||||
useCompressionStream: true,
|
useCompressionStream: true,
|
||||||
preventClose: false,
|
preventClose: false,
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue