Skip to content

Commit

Permalink
fix: close file on readAll exception (#682)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsherret authored Nov 22, 2024
1 parent dcc1aa9 commit 13f0295
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 5 deletions.
1 change: 0 additions & 1 deletion deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export {
} from "jsr:@std/http@^1.0/negotiation";
export { UserAgent } from "jsr:@std/http@^1.0/user-agent";
export { LimitedReader } from "jsr:@std/[email protected]/limited-reader";
export { readAll } from "jsr:@std/[email protected]/read-all";
export { contentType } from "jsr:@std/media-types@^1.0/content-type";
export { typeByExtension } from "jsr:@std/media-types@^1.0/type-by-extension";
export {
Expand Down
6 changes: 2 additions & 4 deletions send.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import {
ifNoneMatch,
parse,
range,
readAll,
responseRange,
Status,
} from "./deps.ts";
Expand Down Expand Up @@ -142,12 +141,11 @@ async function getEntity(
let body: Uint8Array | Deno.FsFile;
let entity: Uint8Array | FileInfo;
const fileInfo = { mtime: new Date(mtime), size: stats.size };
const file = await Deno.open(path, { read: true });
if (stats.size < maxbuffer) {
const buffer = await readAll(file);
file.close();
const buffer = await Deno.readFile(path);
body = entity = buffer;
} else {
const file = await Deno.open(path, { read: true });
response.addResource(file);
body = file;
entity = fileInfo;
Expand Down

0 comments on commit 13f0295

Please sign in to comment.