diff --git a/packages/util-body-length-node/src/calculateBodyLength.spec.ts b/packages/util-body-length-node/src/calculateBodyLength.spec.ts index a25e43cab1d78..ff4de3bd86ae9 100644 --- a/packages/util-body-length-node/src/calculateBodyLength.spec.ts +++ b/packages/util-body-length-node/src/calculateBodyLength.spec.ts @@ -38,9 +38,17 @@ describe(calculateBodyLength.name, () => { expect(calculateBodyLength(view)).toEqual(1); }); - it("should handle stream created using fs.createReadStream", () => { + describe("should handle stream created using fs.createReadStream", () => { const fileSize = lstatSync(__filename).size; - const fsReadStream = createReadStream(__filename); - expect(calculateBodyLength(fsReadStream)).toEqual(fileSize); + + it("when path is a string", () => { + const fsReadStream = createReadStream(__filename); + expect(calculateBodyLength(fsReadStream)).toEqual(fileSize); + }); + + it("when path is a Buffer", () => { + const fsReadStream = createReadStream(Buffer.from(__filename)); + expect(calculateBodyLength(fsReadStream)).toEqual(fileSize); + }); }); }); diff --git a/packages/util-body-length-node/src/calculateBodyLength.ts b/packages/util-body-length-node/src/calculateBodyLength.ts index 888c044d843c3..4669869145a82 100644 --- a/packages/util-body-length-node/src/calculateBodyLength.ts +++ b/packages/util-body-length-node/src/calculateBodyLength.ts @@ -11,7 +11,7 @@ export const calculateBodyLength = (body: any): number | undefined => { return body.byteLength; } else if (typeof body.size === "number") { return body.size; - } else if (typeof body.path === "string") { + } else if (typeof body.path === "string" || Buffer.isBuffer(body.path)) { // handles fs readable streams return lstatSync(body.path).size; }