mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-21 08:03:13 +09:00
ModPack and map exchange strings need synchronous inflate and deflate. In the browser these came from the browserify-zlib polyfill, which brings pako, assert and util along. The browser build now imports fflate through a #zlib_sync subpath import, Node.js keeps node:zlib. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
16 lines
484 B
TypeScript
16 lines
484 B
TypeScript
/* eslint-disable node/no-sync */
|
|
import { strToU8, unzlibSync, zlibSync } from "fflate";
|
|
|
|
export function inflateSync(data: Uint8Array): Uint8Array {
|
|
try {
|
|
return unzlibSync(data);
|
|
} catch (err: any) {
|
|
// Match the error code node:zlib gives for invalid data.
|
|
throw Object.assign(new Error(err.message), { code: "Z_DATA_ERROR" });
|
|
}
|
|
}
|
|
|
|
export function deflateSync(data: Uint8Array | string): Uint8Array {
|
|
return zlibSync(typeof data === "string" ? strToU8(data) : data);
|
|
}
|