Skip to content
Browse files

prevent losing data on long-overflows

  • Loading branch information...
1 parent 22f326a commit 5814ec780fd925c6589a10ce1f91d474c8c66346 @VanCoding committed Mar 22, 2013
Showing with 17 additions and 6 deletions.
  1. +17 −6 lib/index.js
View
23 lib/index.js
@@ -27,7 +27,10 @@ function parseNBT(buffer,index){
return val;
},
4:function(){
- var val = new i64(buffer,index).toNumber();
+ var val = new Number(new i64(buffer,index).toNumber());
+ if(val == Infinity || val == -Infinity){
+ val.buffer = buffer.slice(index,index+7);
+ }
index += 8;
return val;
},
@@ -131,10 +134,14 @@ function buildNBT(data){
bufs.push(b);
},
4:function(data){
- var b = new Buffer(8);
- var i = new i64(b,0);
- i.setValue(data);
- bufs.push(b);
+ if(data.buffer){
+ bufs.push(data.buffer);
+ }else{
+ var b = new Buffer(8);
+ var i = new i64(b,0);
+ i.setValue(data instanceof Number?data.valueOf():data);
+ bufs.push(b);
+ }
},
5:function(data){
var b = new Buffer(4);
@@ -190,7 +197,11 @@ function buildNBT(data){
function type(val){
switch(typeof val){
case "object":
- return (val instanceof Array)?9:((val instanceof Buffer)?7:10);
+ if(val instanceof Number){
+ return 4;
+ }else{
+ return (val instanceof Array)?9:((val instanceof Buffer)?7:10);
+ }
case "number":
if(val % 1 == 0){
if(val < -128 || val > 127){

0 comments on commit 5814ec7

Please sign in to comment.
Something went wrong with that request. Please try again.