From e7d3d00580322321716a2e399a1a36790ea92307 Mon Sep 17 00:00:00 2001 From: devcat Date: Fri, 2 Oct 2020 21:16:21 +0200 Subject: [PATCH] change to zlib zero-copy inflate --- deps.ts | 2 +- src/module/basicShard.ts | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/deps.ts b/deps.ts index 37a594163..776b73054 100644 --- a/deps.ts +++ b/deps.ts @@ -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"; diff --git a/src/module/basicShard.ts b/src/module/basicShard.ts index cdab660e1..19a50802d 100644 --- a/src/module/basicShard.ts +++ b/src/module/basicShard.ts @@ -24,6 +24,7 @@ import { handleDiscordPayload } from "./shardingManager.ts"; const basicShards = new Map(); const heartbeating = new Set(); +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") {