fix(learner): zip buffer types
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
34826762a8
commit
752e44696f
@@ -71,7 +71,7 @@ export function codeRoutes(ctx: ServerContext): Feature["routes"] {
|
||||
const total = files.reduce((s, f) => s + f.size, 0);
|
||||
if (total > MAX_ZIP_BYTES) return json({ error: "this folder is too large to download as one zip" }, 413);
|
||||
const folder = r.code.dir.split("/").filter(Boolean).pop() ?? r.mod.id;
|
||||
const data = zip(files.map((f) => ({ name: `${folder}/${f.path}`, data: readFileSync(f.abs), mtime: lstatSync(f.abs).mtime })));
|
||||
const data = zip(files.map((f) => ({ name: `${folder}/${f.path}`, data: new Uint8Array(readFileSync(f.abs)), mtime: lstatSync(f.abs).mtime })));
|
||||
return new Response(data, {
|
||||
headers: { "Content-Type": "application/zip", "Content-Length": String(data.length), "Content-Disposition": contentDisposition(`${folder}.zip`) },
|
||||
});
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/** Minimal ZIP writer (PKWARE APPNOTE 6.3): deflate or store per entry, CRC-32, UTF-8 names (flag bit 11). No ZIP64. */
|
||||
export interface ZipEntry { name: string; data: Uint8Array; mtime?: Date }
|
||||
export interface ZipEntry { name: string; data: Uint8Array<ArrayBuffer>; mtime?: Date }
|
||||
|
||||
function dosTime(d: Date): { time: number; date: number } {
|
||||
const y = Math.max(1980, d.getFullYear());
|
||||
@@ -9,9 +9,9 @@ function dosTime(d: Date): { time: number; date: number } {
|
||||
};
|
||||
}
|
||||
|
||||
export function zip(entries: ZipEntry[]): Uint8Array {
|
||||
export function zip(entries: ZipEntry[]): Uint8Array<ArrayBuffer> {
|
||||
const enc = new TextEncoder();
|
||||
const locals: Uint8Array[] = [];
|
||||
const locals: Uint8Array<ArrayBuffer>[] = [];
|
||||
const centrals: Uint8Array[] = [];
|
||||
let offset = 0;
|
||||
for (const e of entries) {
|
||||
|
||||
Reference in New Issue
Block a user