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>
26 lines
978 B
JavaScript
26 lines
978 B
JavaScript
/* eslint-disable node/no-sync */
|
|
import assert from "node:assert/strict";
|
|
import zlib from "node:zlib";
|
|
|
|
import * as browserZlib from "../../packages/lib/src/zlib_sync.browser.ts";
|
|
|
|
describe("lib/zlib_sync.browser", function() {
|
|
const text = JSON.stringify({ name: "pack", mods: [{ name: "base", version: "2.0.0" }] });
|
|
|
|
it("should inflate data deflated by node:zlib", function() {
|
|
const inflated = browserZlib.inflateSync(zlib.deflateSync(text));
|
|
assert.equal(Buffer.from(inflated).toString(), text);
|
|
});
|
|
it("should deflate data node:zlib can inflate", function() {
|
|
assert.equal(zlib.inflateSync(browserZlib.deflateSync(text)).toString(), text);
|
|
const bytes = Buffer.from(text);
|
|
assert.equal(zlib.inflateSync(browserZlib.deflateSync(bytes)).toString(), text);
|
|
});
|
|
it("should throw with a Z_ code on invalid data", function() {
|
|
assert.throws(
|
|
() => browserZlib.inflateSync(Buffer.from("not zlib data")),
|
|
err => err.code === "Z_DATA_ERROR"
|
|
);
|
|
});
|
|
});
|