mirror of
https://github.com/MercuryWorkshop/adrift.git
synced 2025-05-13 06:10:01 -04:00
serverside client chunking impl (CURSED)
This commit is contained in:
parent
a839d0fe51
commit
b73a561844
5 changed files with 51 additions and 20 deletions
|
@ -7,7 +7,6 @@ import {
|
|||
ReadyStateCallback,
|
||||
WebSocketImpl,
|
||||
} from "bare-client-custom";
|
||||
import { ReadableStream, TransformStream } from "node:stream/web";
|
||||
import { MAX_CHUNK_SIZE } from "protocol";
|
||||
import { Connection } from "./Connection";
|
||||
|
||||
|
@ -23,6 +22,17 @@ function createBodyStream(
|
|||
): ReadableStream<ArrayBuffer | Uint8Array> | null {
|
||||
if (body === null) return null;
|
||||
|
||||
if (typeof body === "string") {
|
||||
body = new TextEncoder().encode(body);
|
||||
}
|
||||
|
||||
if (ArrayBuffer.isView(body)) {
|
||||
body = body.buffer.slice(
|
||||
body.byteOffset,
|
||||
body.byteOffset + body.byteLength
|
||||
);
|
||||
}
|
||||
|
||||
const transformer = () =>
|
||||
new TransformStream({
|
||||
transform: async (
|
||||
|
@ -82,7 +92,6 @@ function createBodyStream(
|
|||
}
|
||||
|
||||
if (body instanceof Blob) {
|
||||
// @ts-expect-error
|
||||
return body.stream().pipeThrough(transformer());
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue