mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-21 08:03:13 +09:00
Use fflate for zlib in the web interface
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>
This commit is contained in:
1 parent
909f6ab08b
commit
4d7c1020b0
8 files changed
+64
-3
No files matched your search
@@ -0,0 +1,25 @@
|
||||
/* 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"
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user