fix: (regression 0.52.5) zip without calculated size are no longer served

Massimo Melina committed Mar 12, 2025 at 23:33 UTC bdc064ecd71214e73d2c8997d21fa91d6763b040
2 files changed +3 -3
src/serveFile.ts
+3 -2
@@ -133,9 +133,10 @@ declare module "koa" {
133 export function applyRange(ctx: Koa.Context, totalSize=ctx.response.length) {
134 ctx.set('Accept-Ranges', 'bytes')
135 const { range } = ctx.request.header
136 - if (!range) {
136 + if (!range || isNaN(totalSize)) {
137 ctx.state.includesLastByte = true
138 - ctx.response.length = totalSize
138 + if (!isNaN(totalSize))
139 + ctx.response.length = totalSize
140 return
141 }
142 const [unit, ranges] = range.split('=')
src/zip.ts
-1
@@ -73,7 +73,6 @@ export async function zipStreamFromFolder(node: VfsNode, ctx: Koa.Context) {
73 const zip = new QuickZipStream(mappedWalker)
74 const time = 1000 * zipSeconds.get()
75 const size = await zip.calculateSize(time)
76 - ctx.response.length = size
76 const range = applyRange(ctx, size) // keep var size as ctx.response.length won't preserve a NaN
77 if (ctx.status >= 400)
78 return