Skip to content

Commit 843c996

Browse files
committed
fix: update for Uint8Array being generic
1 parent cba0050 commit 843c996

File tree

6 files changed

+21
-21
lines changed

6 files changed

+21
-21
lines changed

body.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ const KNOWN_BODY_TYPES: [bodyType: BodyType, knownMediaTypes: string[]][] = [
3030
];
3131

3232
async function readBlob(
33-
body?: ReadableStream<Uint8Array> | null,
33+
body?: ReadableStream<Uint8Array<ArrayBuffer>> | null,
3434
type?: string | null,
3535
): Promise<Blob> {
3636
if (!body) {
3737
return new Blob(undefined, type ? { type } : undefined);
3838
}
39-
const chunks: Uint8Array[] = [];
39+
const chunks: Uint8Array<ArrayBuffer>[] = [];
4040
for await (const chunk of body) {
4141
chunks.push(chunk);
4242
}
@@ -45,7 +45,7 @@ async function readBlob(
4545

4646
/** An object which encapsulates information around a request body. */
4747
export class Body {
48-
#body?: ReadableStream<Uint8Array> | null;
48+
#body?: ReadableStream<Uint8Array<ArrayBuffer>> | null;
4949
#memo: Promise<ArrayBuffer | Blob | FormData | string> | null = null;
5050
#memoType: "arrayBuffer" | "blob" | "formData" | "text" | null = null;
5151
#headers?: Headers;
@@ -80,7 +80,7 @@ export class Body {
8080
}
8181

8282
/** Exposes the "raw" `ReadableStream` of the body. */
83-
get stream(): ReadableStream<Uint8Array> | null {
83+
get stream(): ReadableStream<Uint8Array<ArrayBuffer>> | null {
8484
return this.#request ? this.#request.body : this.#body!;
8585
}
8686

http_server_bun.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ class BunRequest implements ServerRequest {
9494
#resolved = false;
9595
#promise: Promise<Response>;
9696

97-
get body(): ReadableStream<Uint8Array> | null {
97+
get body(): ReadableStream<Uint8Array<ArrayBuffer>> | null {
9898
return this.#request.body;
9999
}
100100

@@ -150,7 +150,7 @@ class BunRequest implements ServerRequest {
150150
this.#reject(reason);
151151
}
152152

153-
getBody(): ReadableStream<Uint8Array> | null {
153+
getBody(): ReadableStream<Uint8Array<ArrayBuffer>> | null {
154154
return this.#request.body;
155155
}
156156

http_server_native_request.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export class NativeRequest implements ServerRequest {
5555
this.#response = promise;
5656
}
5757

58-
get body(): ReadableStream<Uint8Array> | null {
58+
get body(): ReadableStream<Uint8Array<ArrayBuffer>> | null {
5959
return this.#request.body;
6060
}
6161

@@ -102,7 +102,7 @@ export class NativeRequest implements ServerRequest {
102102
this.#resolved = true;
103103
}
104104

105-
getBody(): ReadableStream<Uint8Array> | null {
105+
getBody(): ReadableStream<Uint8Array<ArrayBuffer>> | null {
106106
return this.#request.body;
107107
}
108108

http_server_node.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,15 @@ export class NodeRequest implements ServerRequest {
9090
this.#responded = true;
9191
}
9292

93-
getBody(): ReadableStream<Uint8Array> | null {
94-
let body: ReadableStream<Uint8Array> | null;
93+
getBody(): ReadableStream<Uint8Array<ArrayBuffer>> | null {
94+
let body: ReadableStream<Uint8Array<ArrayBuffer>> | null;
9595
if (this.method === "GET" || this.method === "HEAD") {
9696
body = null;
9797
} else {
98-
body = new ReadableStream<Uint8Array>({
98+
body = new ReadableStream<Uint8Array<ArrayBuffer>>({
9999
start: (controller) => {
100-
this.#request.on("data", (chunk: Uint8Array) => {
101-
controller.enqueue(chunk);
100+
this.#request.on("data", (chunk) => {
101+
controller.enqueue(chunk as Uint8Array<ArrayBuffer>);
102102
});
103103
this.#request.on("error", (err: Error) => {
104104
controller.error(err);

send.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,9 @@ async function getEntity(
137137
stats: Deno.FileInfo,
138138
maxbuffer: number,
139139
response: Response,
140-
): Promise<[Uint8Array | Deno.FsFile, Uint8Array | FileInfo, FileInfo]> {
141-
let body: Uint8Array | Deno.FsFile;
142-
let entity: Uint8Array | FileInfo;
140+
): Promise<[Uint8Array<ArrayBuffer> | Deno.FsFile, Uint8Array<ArrayBuffer> | FileInfo, FileInfo]> {
141+
let body: Uint8Array<ArrayBuffer> | Deno.FsFile;
142+
let entity: Uint8Array<ArrayBuffer> | FileInfo;
143143
const fileInfo = { mtime: new Date(mtime), size: stats.size };
144144
if (stats.size < maxbuffer) {
145145
const buffer = await Deno.readFile(path);
@@ -270,8 +270,8 @@ export async function send(
270270
: contentTypes[extname(path)] ?? extname(path);
271271
}
272272

273-
let entity: Uint8Array | FileInfo | null = null;
274-
let body: Uint8Array | Deno.FsFile | null = null;
273+
let entity: Uint8Array<ArrayBuffer> | FileInfo | null = null;
274+
let body: Uint8Array<ArrayBuffer> | Deno.FsFile | null = null;
275275
let fileInfo: FileInfo | null = null;
276276

277277
if (request.headers.has("If-None-Match") && mtime) {

types.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export interface ServerRequest {
2121
readonly url: string;
2222
// deno-lint-ignore no-explicit-any
2323
error(reason?: any): void;
24-
getBody(): ReadableStream<Uint8Array> | null;
24+
getBody(): ReadableStream<Uint8Array<ArrayBuffer>> | null;
2525
respond(response: Response): void | Promise<void>;
2626
upgrade?(options?: UpgradeWebSocketOptions): WebSocket;
2727
}
@@ -38,8 +38,8 @@ export interface ServerConstructor<T extends ServerRequest> {
3838
type?: "native" | "node" | "bun";
3939
}
4040

41-
export type Data = string | number[] | ArrayBuffer | Uint8Array;
42-
export type Key = string | number[] | ArrayBuffer | Uint8Array;
41+
export type Data = string | number[] | ArrayBuffer | Uint8Array<ArrayBuffer>;
42+
export type Key = string | number[] | ArrayBuffer | Uint8Array<ArrayBuffer>;
4343

4444
export interface UpgradeWebSocketOptions {
4545
protocol?: string;

0 commit comments

Comments
 (0)