Skip to content

Commit e74a0bf

Browse files
committed
REF: async async stats with async RH for streaming.
1 parent b0551ca commit e74a0bf

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

example/factories.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import {
88
defaultEndpointsFactory,
99
} from "express-zod-api";
1010
import { authMiddleware } from "./middlewares";
11-
import { createReadStream, statSync } from "node:fs";
11+
import { createReadStream } from "node:fs";
12+
import { stat } from "node:fs/promises";
1213
import { z } from "zod/v4";
1314

1415
/** @desc This factory extends the default one by enforcing the authentication using the specified middleware */
@@ -34,12 +35,12 @@ export const fileStreamingEndpointsFactory = new EndpointsFactory(
3435
new ResultHandler({
3536
positive: { schema: ez.buffer(), mimeType: "image/*" },
3637
negative: { schema: z.string(), mimeType: "text/plain" },
37-
handler: ({ response, error, output, request: { method } }) => {
38+
handler: async ({ response, error, output, request: { method } }) => {
3839
if (error) return void response.status(400).send(error.message);
3940
if ("filename" in output && typeof output.filename === "string") {
4041
const target = response.attachment(output.filename);
4142
if (method === "HEAD") {
42-
const { size } = statSync(output.filename);
43+
const { size } = await stat(output.filename);
4344
return void target.set("Content-Length", `${size}`).end();
4445
}
4546
createReadStream(output.filename).pipe(target);

0 commit comments

Comments
 (0)