From cdf9abd428919e9cd34bf62a3493f367e8c53bcc Mon Sep 17 00:00:00 2001 From: Mrgaton <68958481+Mrgaton@users.noreply.github.com> Date: Mon, 26 Aug 2024 22:02:45 +0200 Subject: [PATCH] Brotli compression options and jsc serealizer (#147) Co-authored-by: Ivan Gabaldon --- bun.lockb | Bin 76488 -> 73080 bytes package.json | 1 - src/document/compression.ts | 21 +++++++++++++++++---- src/document/storage.ts | 6 +++--- 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/bun.lockb b/bun.lockb index 17193c90a37f85e28ccf5eb409bb97db9242cde5..0c157eaa320498f64ba576eb5e150b47e3edc114 100755 GIT binary patch delta 12706 zcmeHOdw5OPwqI){k-d>fLS&0A67dL?*G{r`1e>5B@@d`mmh(sQU6xpE&>Jg*f z@h+vbm8M!kOSG!eRvVOhOG{g-J*Brjm4kDCV?7!@pL4%^?!ABA@669{jrp6;F~%Hg zuD!CRkH2*Ny~1^6So@*}FJG$K>mM6jDQw>q)b#%HPsSZ@bLH8KAND9)-fPYM#P7|b z!0Ce$M@z|8S(4wW5Ujo+I6p*%5z<={ga(kqAR9s&AfHw~0{ysrhN~d>Lypp9Z^)+L zp^(iWy&zja{?$e0*C9>dA4B>qN`0()=>E9S=gBVbF z29xr8r_02DLl}$~Qv!5=gGE*2?2C77x1!lKYR#Ng1D-D+rIZ@?IWl`!$eU zKQ%RHQmRD|tf*&yr00fC%E%g5C=_8-9;huUydWp01`Cu1Py2xBCgJ&C}e1WC!}8ocS2&!2a@q&WfFoJdHaf zPx~{XhXY|4+Ht?bX2rZhXEefw9k&*e^p+uv{DuFhvW$lLb65f!TJEH<5S?!Q{de12qf3<*XpOG#t~hJtU8_ zT$3}?(v=WM&rQuw<@<7L8+F3mw(3B~uoUdd1?a$>m~R$BCbuFPSwT*j}9|se>wKrDU*&1YMDm5VgEmle%KvF)42f-W^rN z^B|$Sb0Q=!Wl~34<<_>)KTLJh!%#uM;yHf@XNSy6nVP|RqfBx9PvPo{=_|!I;y73~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/bun": "~1.1.8", - "cbor-x": "~1.6.0", "chalk": "~5.3.0", "env-var": "~7.5.0", "hono": "~4.5.9", diff --git a/src/document/compression.ts b/src/document/compression.ts index eac7373..c56e6d6 100644 --- a/src/document/compression.ts +++ b/src/document/compression.ts @@ -1,11 +1,24 @@ -import { type InputType, brotliCompress, brotliDecompress } from 'node:zlib'; +import { brotliCompress, brotliDecompress, constants as zlibConstants } from 'node:zlib'; import { errorHandler } from '../server/errorHandler.ts'; import { ErrorCode } from '../types/ErrorHandler.ts'; +const compressOptions: { [key: number]: number } = { + [zlibConstants.BROTLI_PARAM_QUALITY]: 11, + [zlibConstants.BROTLI_PARAM_LGWIN]: 28 // 256mb +}; + export const compression = { - encode: (data: InputType): Promise => { + encode: (data: ArrayBuffer): Promise => { return new Promise((resolve, reject) => { - brotliCompress(data, (err, buffer) => { + const isText = Buffer.from(data.slice(0, 1024 * 2)).every( + (byte) => (byte >= 32 && byte <= 126) || byte === 9 || byte === 10 || byte === 13 + ); + + compressOptions[zlibConstants.BROTLI_PARAM_MODE] = isText + ? zlibConstants.BROTLI_MODE_TEXT + : zlibConstants.BROTLI_MODE_GENERIC; + + brotliCompress(data, compressOptions, (err, buffer) => { if (err) { reject(errorHandler.send(ErrorCode.documentCorrupted)); } else { @@ -15,7 +28,7 @@ export const compression = { }); }, - decode: (data: InputType): Promise => { + decode: (data: Uint8Array): Promise => { return new Promise((resolve, reject) => { brotliDecompress(data, (err, buffer) => { if (err) { diff --git a/src/document/storage.ts b/src/document/storage.ts index 41b4946..0067560 100644 --- a/src/document/storage.ts +++ b/src/document/storage.ts @@ -1,4 +1,4 @@ -import { decode, encode } from 'cbor-x'; +import { deserialize, serialize } from 'bun:jsc'; import { config } from '../server.ts'; import { errorHandler } from '../server/errorHandler.ts'; import type { Document } from '../types/Document.ts'; @@ -15,10 +15,10 @@ export const storage = { errorHandler.send(ErrorCode.documentNotFound); } - return decode(Buffer.from(await file.arrayBuffer())); + return deserialize(Buffer.from(await file.arrayBuffer())); }, write: async (name: string, document: Document): Promise => { - await Bun.write(config.storagePath + name, encode(document)); + await Bun.write(config.storagePath + name, serialize(document)); } } as const;