在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):PrismarineJS/prismarine-nbt开源软件地址(OpenSource Url):https://github.com/PrismarineJS/prismarine-nbt开源编程语言(OpenSource Language):JavaScript 100.0%开源软件介绍(OpenSource Introduction):Prismarine-NBTPrismarine-NBT is a JavaScript parser and serializer for NBT archives. It supports big, little, and little-varint encoded NBT files. Usageas a async promiseconst fs = require('fs/promises')
const nbt = require('prismarine-nbt')
async function main(file) {
const buffer = await fs.readFile(file)
const { parsed, type } = await nbt.parse(buffer)
console.log('JSON serialized', JSON.stringify(result, null, 2))
fs.createWriteStream('file.nbt').write(nbt.writeUncompressed(result, type)) // Write it back
}
main('file.nbt') as a callbackvar fs = require('fs'),
nbt = require('prismarine-nbt');
fs.readFile('bigtest.nbt', function(error, data) {
if (error) throw error;
nbt.parse(data, function(error, data) {
console.log(data.value.stringTest.value);
console.log(data.value['nested compound test'].value);
});
}); If the data is gzipped, it is automatically decompressed, for the buffer see metadata.buffer APIparse(data, [format]): Promise<{ parsed, type, metadata: { size, buffer? } }>parse(data, [format,] callback)Takes an optionally compressed If the endian Minecraft Java Edition uses big-endian format, and Bedrock uses little-endian. writeUncompressed(value, format='big')Returns a buffer with a serialized nbt parseUncompressed(data, format='big')Takes a buffer simplify(nbt)Returns a simplified nbt representation : keep only the value to remove one level. This loses the types so you cannot use the resulting representation to write it back to nbt. protos : { big, little, littleVarint }Provides compiled protodef instances used to parse and serialize nbt protoProvide the big-endian protodef instance used to parse and serialize nbt. protoLEProvide the little-endian protodef instance used to parse and serialize little endian nbt. builderProvides a way to build complex nbt structures simply: const nbt = require('prismarine-nbt')
const tag = nbt.comp({
Air: nbt.short(300),
Armor: nbt.list(nbt.comp([
{ Count: nbt.byte(0), Damage: nbt.short(0), Name: nbt.string('a') },
{ Count: nbt.byte(0), Damage: nbt.short(0), Name: nbt.string('b') },
{ Count: nbt.byte(0), Damage: nbt.short(0), Name: nbt.string('c') }
]))
})
nbt.writeUncompressed(tag) // now do something with this nbt buffer... See index.d.ts for methods Browser usageFor webpack usage, see an example configuration here. For a web bundle with browserify (after you ran
<script src="./pnbt.js"></script>
<script>
const nbt = require('prismarine-nbt')
const { Buffer } = require('buffer')
fetch('test.nbt').then(resp => resp.arrayBuffer())
.then(buf => nbt.parse(Buffer.from(buf))).then(console.log)
</script> |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论