Skip to content

Commit

Permalink
Small Lobby Streamline
Browse files Browse the repository at this point in the history
I need to better account for compression differences with my tests, as right now it depends on which zlib compression implementation you write your NBT files with, will depend on whether the tests will pass or not. This should be excluded I think, I thought it would be perfect to ensure that the compressed versions are the exact same as well, but I don't think that's worthwhile if you can check the raw bytes themselves anyways.

Say, to make this file recompiled with the matching zlib layouts, and with the newly updated empty ListTag types ( #40 ), simply opening it with Dovetail and re-saving it didn't work, because it looks like Chrome's zlib backing is different than Node's, even though they both use V8, and they are both on the same macOS ARM machine. So I can rule those things out. I already knew this was the case between Linux and macOS, but I thought this wasn't different between Chrome and Node on the same machine for some reason. I guess I assumed that they would *happen* to be using the same compression implementations, even if they may be two separate installations of that. That would make sense, I didn't expect them to use the same install of it. Just the same or nearly same versions.

Another weird thing I encountered. Since I discovered the zlib differences between Node and the browser, I thought I'd use my local global install of NBTify in the CLI to resave the file, using Node as well. That actually encountered an error, and it was only happening with the `--pipe` flag to write it back to the original file. I'm not sure what it was about, that was frustrating though. Going to look into debugging that one. #25
  • Loading branch information
Offroaders123 committed Nov 28, 2023
1 parent e9ccf44 commit eba8dc8
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 20 deletions.
5 changes: 0 additions & 5 deletions src/read.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,11 +315,6 @@ export class NBTReader {
const entry = this.#readTag(type);
value.push(entry);
}

if (length < 1){
console.log("read:",type,value);
}

return value;
}

Expand Down
5 changes: 0 additions & 5 deletions src/write.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,11 +250,6 @@ export class NBTWriter {
value = value.filter(isTag);
const type: TAG = (value[0] !== undefined) ? getTagType(value[0]) : TAG.END;
const { length } = value;

if (length < 1){
console.log("write:",type,value);
}

this.#writeTagType(type);
this.#writeInt(length);
for (const entry of value){
Expand Down
13 changes: 3 additions & 10 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,27 +59,20 @@ describe("Read, Stringify, Parse and Write",() => {
const compression = (result instanceof NBT.NBTData)
? result.compression
: null;
const header = (compression !== null && compression !== "deflate-raw" && !name.endsWith(".schem")) ? 10 : 0;
const header = (compression !== null && compression !== "deflate-raw") ? 10 : 0;

let control: Buffer | Uint8Array = (snbt)
const control = (snbt)
? Buffer.from(stringified)
: buffer.subarray(header);

let experiment = recompile.subarray(header);

// if (name.endsWith(".schem")){
// control = await NBT.decompress(control,"gzip");
// experiment = await NBT.decompress(experiment,"gzip");
// }
const experiment = recompile.subarray(header);

/**
* Compare the original NBT file buffer to that of the recompiled buffer,
* ensure that they are byte-for-byte the same, asserting that NBTify has
* it's formats implemented correctly!
*/
const compare = Buffer.compare(control,experiment);
// if (name.endsWith("schem")) console.log(control.join(" "),"\n");
// if (name.endsWith("schem")) console.log(experiment.join(" "));
strictEqual(compare,0,`'${name}' does not symmetrically recompile`);
});
}
Expand Down

0 comments on commit eba8dc8

Please sign in to comment.