{"name":"prismarine-nbt","version":"2.3.0","description":"A parser and serializer for NBT archives","keywords":["nbt","minecraft"],"homepage":"https://github.com/prismarinejs/prismarine-nbt","author":{"name":"roblabla","email":"robinlambertz+dev@gmail.com"},"maintainers":[{"name":"rom1504","email":"romain.rom1@gmail.com"},{"name":"wtfaremyinitials","email":"wtfranzen@gmail.com"},{"name":"roblabla","email":"robinlambertz.dev@gmail.com"}],"main":"nbt","types":"./typings/index.d.ts","repository":{"type":"git","url":"git+https://github.com/prismarinejs/prismarine-nbt.git"},"devDependencies":{"chai":"^4.2.0","mocha":"^10.0.0","standard":"^17.0.0"},"scripts":{"test":"mocha --reporter spec","pretest":"npm run lint","lint":"standard","fix":"standard --fix"},"dependencies":{"protodef":"^1.9.0"},"license":"MIT","gitHead":"1c62910515ab78b0599ea0700371c34811f5b0a9","bugs":{"url":"https://github.com/prismarinejs/prismarine-nbt/issues"},"_id":"prismarine-nbt@2.3.0","_nodeVersion":"18.0.0","_npmVersion":"8.6.0","dist":{"integrity":"sha512-awxt0iQsad2X0sVr0frDLfjggLwJuIm+p4cZQc9/Xx466rLlgF6y1CVJkVEH9qTVo8zUb70VJLq984z2YYuntg==","shasum":"bc170792f32c5d3f823339cbba371f1acdac447e","tarball":"http://registry-npm.ywwl.com/prismarine-nbt/download/prismarine-nbt-2.3.0.tgz","fileCount":32,"unpackedSize":1085683,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDpFyX6PuQZ9awZJtzxhgNCjPDcBh9dLrtgDBXZ7JeA8wIhAICNsjk9ZAkLig2yno7yywfCglxr4PW0kCVGC/jApwTI"}],"size":50048,"noattachment":false,"key":"/prismarine-nbt/-/prismarine-nbt-2.3.0.tgz"},"_npmUser":{"name":"rom1504","email":"romain.rom1@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/prismarine-nbt_2.3.0_1702831494849_0.9447761143636675"},"_hasShrinkwrap":false,"readme":"# Prismarine-NBT\n[![NPM version](https://img.shields.io/npm/v/prismarine-nbt.svg)](http://npmjs.com/package/prismarine-nbt)\n[![Build Status](https://github.com/PrismarineJS/prismarine-nbt/workflows/CI/badge.svg)](https://github.com/PrismarineJS/prismarine-nbt/actions?query=workflow%3A%22CI%22)\n[![Discord](https://img.shields.io/badge/chat-on%20discord-brightgreen.svg)](https://discord.gg/GsEFRM8)\n[![Try it on gitpod](https://img.shields.io/badge/try-on%20gitpod-brightgreen.svg)](https://gitpod.io/#https://github.com/PrismarineJS/prismarine-nbt)\n\nPrismarine-NBT is a JavaScript parser and serializer for [NBT](http://wiki.vg/NBT) archives. It supports big, little, and little-varint encoded NBT files.\n\n\n## Usage\n\n#### as a async promise\n\n```js\nconst fs = require('fs')\nconst nbt = require('prismarine-nbt')\n\nasync function main(file) {\n  const buffer = fs.readFileSync(file)\n  const { parsed, type } = await nbt.parse(buffer)\n  console.log('JSON serialized', JSON.stringify(parsed, null, 2))\n  fs.createWriteStream('bigtest.nbt').write(nbt.writeUncompressed(parsed, type)) // Write it back \n}\nmain('bigtest.nbt')\n```\n\n#### as a callback\n\n```js\nvar fs = require('fs'),\n    nbt = require('prismarine-nbt');\n\nfs.readFile('bigtest.nbt', function(error, data) {\n    if (error) throw error;\n\n    nbt.parse(data, function(error, data) {\n        console.log(data.value.stringTest.value);\n        console.log(data.value['nested compound test'].value);\n    });\n});\n```\n\nIf the data is gzipped, it is automatically decompressed, for the buffer see metadata.buffer\n\n## API\n\n### parse(data, [format]): Promise<{ parsed, type, metadata: { size, buffer? } }>\n### parse(data, [format,] callback)\n\nTakes an optionally compressed `data` buffer and reads the nbt data.\n\nIf the endian `format` is known, it can be specified as 'big', 'little' or 'littleVarint'. If not specified, the library will\ntry to sequentially load as big, little and little varint until the parse is successful. The deduced type is returned as `type`.\n\nMinecraft Java Edition uses big-endian format, and Bedrock uses little-endian.\n\n### writeUncompressed(value, format='big')\n\nReturns a buffer with a serialized nbt `value`. \n\n### parseUncompressed(data, format='big')\n\nTakes a buffer `data` and returns a parsed nbt value.\n\n\n### simplify(nbt)\n\nReturns a simplified nbt representation : keep only the value to remove one level.\nThis loses the types so you cannot use the resulting representation to write it back to nbt.\n\n### equal(nbt1, nbt2)\n\nChecks whether two NBT objects are equal, returns a boolean.\n\n### protos : { big, little, littleVarint }\n\nProvides compiled protodef instances used to parse and serialize nbt\n\n### proto\n\nProvide the big-endian protodef instance used to parse and serialize nbt.\n\n### protoLE\n\nProvide the little-endian protodef instance used to parse and serialize little endian nbt.\n\n### addTypesToCompiler (type, compiler)\nAdds prismarine-nbt types to an ProtoDef compiler instance\n\n### addTypesToInterpreter (type, interperter)\nAdds prismarine-nbt types to a ProtoDef interpreter instance\n\n### builder\n\nProvides a way to build complex nbt structures simply:\n\n```js\nconst nbt = require('prismarine-nbt')\nconst tag = nbt.comp({\n  Air: nbt.short(300),\n  Armor: nbt.list(nbt.comp([\n    { Count: nbt.byte(0), Damage: nbt.short(0), Name: nbt.string('a') },\n    { Count: nbt.byte(0), Damage: nbt.short(0), Name: nbt.string('b') },\n    { Count: nbt.byte(0), Damage: nbt.short(0), Name: nbt.string('c') }\n  ]))\n})\nnbt.writeUncompressed(tag) // now do something with this nbt buffer...\n```\n\nSee [index.d.ts](typings/index.d.ts#L69) for methods\n\n## Browser usage\n\nFor webpack usage, see an example configuration [here](https://github.com/PrismarineJS/prismarine-web-client/blob/master/webpack.common.js#L28).\n\nFor a web bundle with browserify (after you ran `npm install prismarine-nbt` in your project):\n```\nnpx browserify -r prismarine-nbt -r buffer -o pnbt.js\n```\n```html\n<script src=\"./pnbt.js\"></script>\n<script>\n  const nbt = require('prismarine-nbt')\n  const { Buffer } = require('buffer')\n  fetch('test.nbt').then(resp => resp.arrayBuffer())\n    .then(buf => nbt.parse(Buffer.from(buf))).then(console.log)\n</script>\n```\n","publish_time":1702831495008,"_cnpm_publish_time":1702831495008,"dist-tags":{"latest":"2.8.0"}}