+
Profile
diff --git a/packages/server/src/route/comic.ts b/packages/server/src/route/comic.ts
index 2dd34ea..7991e4c 100644
--- a/packages/server/src/route/comic.ts
+++ b/packages/server/src/route/comic.ts
@@ -1,11 +1,11 @@
-import { type Context, DefaultContext, DefaultState, Next } from "koa";
+import type { Context } from "koa";
import Router from "koa-router";
import { createReadableStreamFromZip, entriesByNaturalOrder, readZip } from "../util/zipwrap";
import type { ContentContext } from "./context";
import { since_last_modified } from "./util";
import type { ZipReader } from "@zip.js/zip.js";
import type { FileHandle } from "node:fs/promises";
-import { Readable, Writable } from "node:stream";
+import { Readable } from "node:stream";
/**
* zip stream cache.
@@ -91,11 +91,15 @@ async function renderZipImage(ctx: Context, path: string, page: number) {
},
close() {
nodeReadableStream.push(null);
- releaseZip(path);
- // setTimeout(() => {
- // }, 500);
},
}));
+ nodeReadableStream.on("error", (err) => {
+ console.error(err);
+ releaseZip(path);
+ });
+ nodeReadableStream.on("close", () => {
+ releaseZip(path);
+ });
ctx.body = nodeReadableStream;
ctx.response.length = entry.uncompressedSize;
diff --git a/packages/server/src/util/zipwrap.ts b/packages/server/src/util/zipwrap.ts
index 8699d84..187655f 100644
--- a/packages/server/src/util/zipwrap.ts
+++ b/packages/server/src/util/zipwrap.ts
@@ -4,15 +4,12 @@ import { ZipReader, Reader, type Entry } from "@zip.js/zip.js";
class FileReader extends Reader {
private fd: FileHandle;
- private offset: number;
constructor(fd: FileHandle) {
super(fd);
this.fd = fd;
- this.offset = 0;
}
async init(): Promise {
- this.offset = 0;
this.size = (await this.fd.stat()).size;
}
close(): void {