Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
extremeheat committed Dec 29, 2020
1 parent e771947 commit 6365941
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
node_modules/
package-lock.json
*.nbt
*.dat
*.dat
*.json
!package.json
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ A simple command line Node.js tool to read and write NBT files to JSON and back.

Uses `prismarine-nbt` for serialization and deserialization, see https://github.com/PrismarineJS/prismarine-nbt for more info on schema.

### Usage

via npx:
`npx nbt-dump --help`

via npm:
`npm install -g nbt-dump`
`nbt-dump --help`

```sh
usage, feel free to use natural language:
Parse an NBT file to JSON:
Expand Down
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env node
const fs = require('fs')
const nbt = require('prismarine-nbt')

Expand Down Expand Up @@ -38,7 +39,6 @@ function main(args, argsStr) {
if (files.length == 2) return write(...files, getFmt())
} else {
if (!files.length) files = [args[0], args[0] + '.json']
// if (files.length == 1) files.push(files[0] + '.json')
return read(files[0], files[1], getFmt())
}

Expand Down Expand Up @@ -69,11 +69,11 @@ async function read(inpf, outf, fmt) {
const buffer = await fs.promises.readFile(inpf)
const { result, type } = await nbt.parse(buffer, fmt)

if (!fmt) console.log(`(as ${type} endian)`)
if (outf) {
const json = JSON.stringify(result, (k, v) => typeof v === 'bigint' ? v.toString() : v)
fs.writeFileSync(outf, json)
} else {
if (!fmt) console.log(`(as ${type} endian)`)
console.log(nbt.simplify(result))
}

Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
"version": "1.0.0",
"description": "Read and write Minecraft Named Binary Tag files in big, little and little-varint encoding",
"main": "index.js",
"bin": "index.js",
"bin": {
"nbt-dump": "./index.js"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
Expand Down

0 comments on commit 6365941

Please sign in to comment.