From 35d04ff42eb95fcf610f8f840e29e5c6a6acecbc Mon Sep 17 00:00:00 2001 From: Philipp Borgers Date: Mon, 21 Jan 2013 14:08:49 +0100 Subject: [PATCH] fix jshint errors for lib/writer.js --- lib/writer.js | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/lib/writer.js b/lib/writer.js index 49aed26d..d31f26fb 100644 --- a/lib/writer.js +++ b/lib/writer.js @@ -18,34 +18,34 @@ p._ensure = function(size) { this.buffer = new Buffer(oldBuffer.length + size); oldBuffer.copy(this.buffer); } -} +}; p.addInt32 = function(num) { - this._ensure(4) - this.buffer[this.offset++] = (num >>> 24 & 0xFF) - this.buffer[this.offset++] = (num >>> 16 & 0xFF) - this.buffer[this.offset++] = (num >>> 8 & 0xFF) - this.buffer[this.offset++] = (num >>> 0 & 0xFF) + this._ensure(4); + this.buffer[this.offset++] = (num >>> 24 & 0xFF); + this.buffer[this.offset++] = (num >>> 16 & 0xFF); + this.buffer[this.offset++] = (num >>> 8 & 0xFF); + this.buffer[this.offset++] = (num >>> 0 & 0xFF); return this; -} +}; p.addInt16 = function(num) { - this._ensure(2) - this.buffer[this.offset++] = (num >>> 8 & 0xFF) - this.buffer[this.offset++] = (num >>> 0 & 0xFF) + this._ensure(2); + this.buffer[this.offset++] = (num >>> 8 & 0xFF); + this.buffer[this.offset++] = (num >>> 0 & 0xFF); return this; -} +}; //for versions of node requiring 'length' as 3rd argument to buffer.write var writeString = function(buffer, string, offset, len) { buffer.write(string, offset, len); -} +}; //overwrite function for older versions of node if(Buffer.prototype.write.length === 3) { writeString = function(buffer, string, offset, len) { buffer.write(string, offset); - } + }; } p.addCString = function(string) { @@ -61,40 +61,40 @@ p.addCString = function(string) { this.buffer[this.offset++] = 0; // null terminator return this; -} +}; p.addChar = function(char) { this._ensure(1); writeString(this.buffer, char, this.offset, 1); this.offset++; return this; -} +}; p.addString = function(string) { - var string = string || ""; + string = string || ""; var len = Buffer.byteLength(string); this._ensure(len); this.buffer.write(string, this.offset); this.offset += len; return this; -} +}; p.getByteLength = function() { return this.offset - 5; -} +}; p.add = function(otherBuffer) { this._ensure(otherBuffer.length); otherBuffer.copy(this.buffer, this.offset); this.offset += otherBuffer.length; return this; -} +}; p.clear = function() { this.offset = 5; this.headerPosition = 0; this.lastEnd = 0; -} +}; //appends a header block to all the written data since the last //subsequent header or to the beginning if there is only one data block @@ -103,7 +103,7 @@ p.addHeader = function(code, last) { this.offset = this.headerPosition; this.buffer[this.offset++] = code; //length is everything in this packet minus the code - this.addInt32(origOffset - (this.headerPosition+1)) + this.addInt32(origOffset - (this.headerPosition+1)); //set next header position this.headerPosition = origOffset; //make space for next header @@ -112,19 +112,19 @@ p.addHeader = function(code, last) { this._ensure(5); this.offset += 5; } -} +}; p.join = function(code) { if(code) { this.addHeader(code, true); } return this.buffer.slice(code ? 0 : 5, this.offset); -} +}; p.flush = function(code) { var result = this.join(code); this.clear(); return result; -} +}; module.exports = Writer;