From 07863f6e32b5e539e9c7a24155d1ef926d275ff2 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Wed, 4 Dec 2024 01:37:30 +0100 Subject: [PATCH] feat(node): add `NodeRequestProxy.bytes()` --- src/node-utils/request.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/node-utils/request.ts b/src/node-utils/request.ts index b08342b..05ec483 100644 --- a/src/node-utils/request.ts +++ b/src/node-utils/request.ts @@ -137,6 +137,16 @@ export const NodeRequestProxy = /* @__PURE__ */ (() => return this.#rawBody.then((buff) => buff.buffer as ArrayBuffer); } + bytes(): Promise { + if (!this.#rawBody) { + const _bodyStream = this.body; + return _bodyStream + ? _readStream(_bodyStream) + : Promise.resolve(new Uint8Array()); + } + return this.#rawBody; + } + blob(): Promise { if (!this.#blobBody) { this.#blobBody = this.arrayBuffer().then((buff) => {