Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This was an interesting one! Thankfully I found an issue page about MUTF-8 handling on the repo for Twoolie/NBT, the Python project. It gave me some insight and a file to test against. I wrote my own script to slim it down a bunch, and dedupe the tags that are used multiple times. It's crazy how big just book text can get! I used this actual version of NBTify in this commit, to write the new content to the file. That's also why I diffed it out, I wanted to make sure when I slimmed it down that the content coming out of it was actually what it was supposed to be as well. When using older NBTify, it didn't work correctly, because MUTF-8 handles things different than standard UTF-8. ```js // @ts-check import { readFile, writeFile } from "node:fs/promises"; import * as NBT from "./NBTify/src/index.ts"; const data = await readFile("./hotbar.nbt"); const trimmed = data.subarray(0x000BAE96, 0x000CA7C2); console.log(trimmed); /** @type {NBT.NBTData<any>} */ const hotbar = await NBT.read(data); const book = hotbar.data[0][1].tag.BlockEntityTag.Items[12]; console.log(book); const mutf8Demo = await NBT.write(book); console.log(mutf8Demo); const demoDiff = mutf8Demo.subarray(1, -2); console.log(Buffer.compare(trimmed, demoDiff)); await writeFile("./alien-book.nbt", mutf8Demo); ``` #42 #44 twoolie/NBT#144 (comment) twoolie/NBT#144 I'm still not sure I'm going to use the dependency itself or if I should just emded that into NBTify on it's own. I think I may just use it as a dependency, as I've been trying to get more used to not reinventing the wheel for everything, unless that has benefits. The MUTF-8 library already does everything I need it to, and it's ESM TypeScript, so I'm not sure what other reason I have to not just use it, it's great! Eventually I want to move my compression handling into a separate module too, so I will have to use module resolution for that down the road either way. I say heck to it! Let's do it :) Gonna look into if there's anything I'm forgetting, before doing that though. I really like having the ability to use projects like these (NBTify) without needing a transpilation or build step. Modern CDNs seem to handle this nicely, so we'll see.
- Loading branch information