Skip to content
This repository has been archived by the owner on Mar 19, 2024. It is now read-only.

Commit

Permalink
Return to the old return value of parseUncompressed
Browse files Browse the repository at this point in the history
This reverts two changes: first, returning the size from
 `parseUncompressed` together with the data, rather than just the data;
second, returning both the name and the value of the root node as values
(`{root: <name>, value: <value>}`) rather than a key/value pair
(`{<name>: <value>}` or just `<value>` if no name).

Concerning the read offset as a return value, that definitely doesn't
belong there. If that value is required it should be exposed elsewhere
on the object rather than being tacked onto the value.
  • Loading branch information
sjmulder committed Oct 2, 2015
1 parent fb860b3 commit 16e6c1a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
11 changes: 9 additions & 2 deletions nbt.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,15 @@
var name = reader.string();
var value = reader.compound();

var result = { size: reader.offset, value: { root: name, value: value } };
return result;
// The root is a key/value pair. If the key is empty,
// just return the value.
if (name === '') {
return value;
} else {
var result = {};
result[name] = value;
return result;
}
};

this.parse = function(data, callback) {
Expand Down
7 changes: 3 additions & 4 deletions test/nbt-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ describe('nbt.parse', function() {
nbt.parse(data, function(err, data) {
if (err)
throw error;
expect(data.value.root).to.equal('Level');
expect(data.value.value.stringTest.value).to.equal(
'HELLO WORLD THIS IS A TEST STRING ÅÄÖ!');
expect(data.value.value['nested compound test'].value).to.deep.equal({
expect(data.Level.stringTest.value).to.equal(
'HELLO WORLD THIS IS A TEST STRING ÅÄÖ!');
expect(data.Level['nested compound test'].value).to.deep.equal({
ham: {
type: "compound",
value: {
Expand Down

0 comments on commit 16e6c1a

Please sign in to comment.