From 644d20406bf4add3a2e34c4085de73baff1bf1c2 Mon Sep 17 00:00:00 2001 From: Andrew Wilson Date: Wed, 14 Mar 2012 13:18:00 -0400 Subject: [PATCH] Refactored cut and paste on read long --- lib/parser.js | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/lib/parser.js b/lib/parser.js index 299f556..fcdacf7 100644 --- a/lib/parser.js +++ b/lib/parser.js @@ -77,14 +77,17 @@ Parser.prototype.writeDouble = function(value) { ctype.wdouble(value, endian, this.buffer, (this.position += 8) - 8); }; +Parser.prototype.readLongBytes = function() { + var bytes = [], numBytes = 8; + for (var i = 0; i < numBytes; i++) { + bytes.push(ctype.ruint8(this.buffer, endian, this.position + i)); + } + this.position += numBytes; + return (new BigInteger(bytes)); +}; Parser.prototype.readLong = function() { - var bytes = [], numBytes = 8; - for (var i = 0; i < numBytes; i++) { - bytes.push(ctype.ruint8(this.buffer, endian, this.position + i)); - } - this.position += numBytes; - return (new BigInteger(bytes))[0]; + return this.readLongBytes()[0]; }; Parser.prototype.writeLong = function(value) { var bytes, numBytes = 8; @@ -117,18 +120,9 @@ Parser.prototype.writeString = function(value) { this.position += length; }; -Parser.prototype.readDateBytes = function() { - var bytes = [], numBytes = 8; - for (var i = 0; i < numBytes; i++) { - bytes.push(ctype.ruint8(this.buffer, endian, this.position + i)); - } - this.position += numBytes; - return (new BigInteger(bytes)); -}; - Parser.prototype.readDate = function(value) { var bigInt, i = 0, numBytes = 8; - bigInt = this.readDateBytes(); + bigInt = this.readLongBytes(); var intStr = bigInt.divide(thousand).toString(); return new Date(parseInt(intStr)); };