change to zlib zero-copy inflate

This commit is contained in:
devcat
2020-10-02 21:16:21 +02:00
parent d239e430db
commit e7d3d00580
2 changed files with 7 additions and 2 deletions
+1 -1
View File
@@ -7,4 +7,4 @@ export {
isWebSocketPongEvent,
} from "https://deno.land/std@0.67.0/ws/mod.ts";
export type { WebSocket } from "https://deno.land/std@0.67.0/ws/mod.ts";
export { decompress as inflate } from "https://unpkg.com/@evan/wasm@0.0.9/target/zlib/deno.js";
export { decompress_with as inflate } from "https://unpkg.com/@evan/wasm@0.0.11/target/zlib/deno.js";
+6 -1
View File
@@ -24,6 +24,7 @@ import { handleDiscordPayload } from "./shardingManager.ts";
const basicShards = new Map<number, BasicShard>();
const heartbeating = new Set<number>();
const utf8decoder = new TextDecoder();
export interface BasicShard {
id: number;
@@ -109,7 +110,11 @@ export async function createBasicShard(
}
if (message instanceof Uint8Array) {
message = new TextDecoder().decode(inflate(message, 9));
message = inflate(
message,
0,
(slice: Uint8Array) => utf8decoder.decode(slice),
);
}
if (typeof message === "string") {