buffercursor
Advanced tools
Comparing version 0.0.3 to 0.0.4
@@ -22,4 +22,5 @@ // Copyright 2012 Timothy J Fontaine <tjfontaine@gmail.com> | ||
var assert = require('assert'); | ||
var util = require('util'); | ||
var BufferCursor = module.exports = function (buff) { | ||
var BufferCursor = module.exports = function(buff) { | ||
if (!(this instanceof BufferCursor)) | ||
@@ -33,8 +34,13 @@ return new BufferCursor(buff); | ||
BufferCursor.prototype._move = function (step) { | ||
assert(this._pos + step <= this.buffer.length, "Cannot read beyond buffer"); | ||
var BCO = BufferCursor.BufferCursorOverflow = function() { | ||
Error.apply(this, Array.prototype.slice(arguments)); | ||
}; | ||
util.inherits(BCO, Error); | ||
BufferCursor.prototype._move = function(step) { | ||
assert(this._pos + step <= this.buffer.length, 'Cannot read beyond buffer'); | ||
this._pos += step; | ||
}; | ||
BufferCursor.prototype._read = function (method, size) { | ||
BufferCursor.prototype._read = function(method, size) { | ||
var ret = this.buffer[method](this._pos); | ||
@@ -45,3 +51,6 @@ this._move(size); | ||
BufferCursor.prototype._write = function (value, method, size) { | ||
BufferCursor.prototype._write = function(value, method, size) { | ||
if (this._pos + size > this.length) | ||
throw new BCO(); | ||
this.buffer[method](value, this._pos); | ||
@@ -51,13 +60,13 @@ this._move(size); | ||
BufferCursor.prototype.seek = function (pos) { | ||
assert(pos >= 0, "Cannot seek behind 0"); | ||
assert(pos <= this.buffer.length, "Cannot seek beyond buffer length"); | ||
BufferCursor.prototype.seek = function(pos) { | ||
assert(pos >= 0, 'Cannot seek behind 0'); | ||
assert(pos <= this.buffer.length, 'Cannot seek beyond buffer length'); | ||
this._pos = pos; | ||
}; | ||
BufferCursor.prototype.eof = function () { | ||
BufferCursor.prototype.eof = function() { | ||
return this._pos == this.length; | ||
}; | ||
BufferCursor.prototype.toByteArray = function (method) { | ||
BufferCursor.prototype.toByteArray = function(method) { | ||
var arr = [], i, part; | ||
@@ -78,10 +87,11 @@ | ||
} | ||
return arr; | ||
}; | ||
BufferCursor.prototype.tell = function () { | ||
BufferCursor.prototype.tell = function() { | ||
return this._pos; | ||
}; | ||
BufferCursor.prototype.slice = function (length) { | ||
BufferCursor.prototype.slice = function(length) { | ||
var end, b; | ||
@@ -101,3 +111,3 @@ | ||
BufferCursor.prototype.toString = function (encoding, length) { | ||
BufferCursor.prototype.toString = function(encoding, length) { | ||
var end, ret; | ||
@@ -120,3 +130,3 @@ | ||
BufferCursor.prototype.write = function (value, length, encoding) { | ||
BufferCursor.prototype.write = function(value, length, encoding) { | ||
var end, ret; | ||
@@ -129,3 +139,3 @@ | ||
BufferCursor.prototype.fill = function (value, length) { | ||
BufferCursor.prototype.fill = function(value, length) { | ||
var end; | ||
@@ -147,7 +157,5 @@ | ||
2: ['readUInt16BE', 'readUInt16LE', 'readInt16BE', 'readInt16LE'], | ||
4: [ | ||
'readUInt32BE', 'readUInt32BE', 'readInt32BE', 'readInt32LE', | ||
'readFloatBE', 'readFloatLE', | ||
], | ||
8: ['readDoubleBE', 'readDoubleLE'], | ||
4: ['readUInt32BE', 'readUInt32BE', 'readInt32BE', 'readInt32LE', | ||
'readFloatBE', 'readFloatLE'], | ||
8: ['readDoubleBE', 'readDoubleLE'] | ||
}, | ||
@@ -157,15 +165,13 @@ writer: { | ||
2: ['writeUInt16BE', 'writeUInt16LE', 'writeInt16BE', 'writeInt16LE'], | ||
4: [ | ||
'writeUInt32BE', 'writeUInt32BE', 'writeInt32BE', 'writeInt32LE', | ||
'writeFloatBE', 'writeFloatLE', | ||
], | ||
8: ['writeDoubleBE', 'writeDoubleBE'], | ||
}, | ||
} | ||
4: ['writeUInt32BE', 'writeUInt32BE', 'writeInt32BE', 'writeInt32LE', | ||
'writeFloatBE', 'writeFloatLE'], | ||
8: ['writeDoubleBE', 'writeDoubleBE'] | ||
} | ||
}; | ||
Object.keys(defs.reader).forEach(function (size) { | ||
Object.keys(defs.reader).forEach(function(size) { | ||
var arr = defs.reader[size]; | ||
var move = parseInt(size); | ||
arr.forEach(function (method) { | ||
BufferCursor.prototype[method] = function () { | ||
arr.forEach(function(method) { | ||
BufferCursor.prototype[method] = function() { | ||
return this._read(method, move); | ||
@@ -176,7 +182,7 @@ }; | ||
Object.keys(defs.writer).forEach(function (size) { | ||
Object.keys(defs.writer).forEach(function(size) { | ||
var arr = defs.writer[size]; | ||
var move = parseInt(size); | ||
arr.forEach(function (method) { | ||
BufferCursor.prototype[method] = function (value) { | ||
arr.forEach(function(method) { | ||
BufferCursor.prototype[method] = function(value) { | ||
return this._write(value, method, move); | ||
@@ -183,0 +189,0 @@ }; |
{ | ||
"name": "buffercursor", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"author": "Timothy J Fontaine <tjfontaine@gmail.com> (http://atxconsulting.com)", | ||
@@ -5,0 +5,0 @@ "description": "A simple way to traverse a Buffer like a cursor, updating position along the way", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Non-existent author
Supply chain riskThe package was published by an npm account that no longer exists.
Found 1 instance in 1 package
6918
148
0
1