Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

buffercursor

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

buffercursor - npm Package Compare versions

Comparing version 0.0.9 to 0.0.10

48

buffercursor.js

@@ -21,4 +21,4 @@ // Copyright 2012 Timothy J Fontaine <tjfontaine@gmail.com>

var assert = require('assert');
var util = require('util');
var VError = require('verror');

@@ -41,8 +41,8 @@ var BufferCursor = module.exports = function(buff, noAssert) {

var BCO = BufferCursor.BufferCursorOverflow = function() {
Error.apply(this, Array.prototype.slice(arguments));
VError.apply(this, Array.prototype.slice.call(arguments, 0));
};
util.inherits(BCO, Error);
util.inherits(BCO, VError);
BufferCursor.prototype._move = function(step) {
assert(this._pos + step <= this.buffer.length, 'Cannot read beyond buffer');
this._checkWrite(step);
this._pos += step;

@@ -52,9 +52,36 @@ };

BufferCursor.prototype._checkWrite = function(size) {
if (this._pos + size > this.length)
throw new BCO();
var shouldThrow = false;
var length = this.length;
var pos = this._pos;
if (size > length)
shouldThrow = true;
if (length - pos < size)
shouldThrow = true;
if (shouldThrow) {
var bco = new BCO('BufferCursorOverflow: length %d, position %d, size %d',
length,
pos,
size);
bco.kind = 'BufferCursorOverflow';
bco.length = length;
bco.position = pos;
bco.size = size;
throw bco;
}
}
BufferCursor.prototype.seek = function(pos) {
assert(pos >= 0, 'Cannot seek behind 0');
assert(pos <= this.buffer.length, 'Cannot seek beyond buffer length');
if (pos < 0)
throw new VError(new RangeError('Cannot seek before start of buffer'),
'Negative seek values not allowed: %d', pos);
if (pos > this.length)
throw new VError(new RangeError('Trying to seek beyond buffer'),
'Requested %d position is beyond length %d',
pos, this.length);
this._pos = pos;

@@ -126,2 +153,5 @@ return this;

// This method doesn't need to _checkWrite because Buffer implicitly truncates
// to the length of the buffer, it's the only method in Node core that behaves
// this way by default
BufferCursor.prototype.write = function(value, length, encoding) {

@@ -144,2 +174,4 @@ var end, ret;

this._checkWrite(end - this._pos);
this.buffer.fill(value, this._pos, end);

@@ -146,0 +178,0 @@ this.seek(end);

5

package.json
{
"name": "buffercursor",
"version": "0.0.9",
"version": "0.0.10",
"author": "Timothy J Fontaine <tjfontaine@gmail.com> (http://atxconsulting.com)",

@@ -22,3 +22,6 @@ "description": "A simple way to traverse a Buffer like a cursor, updating position along the way",

"node": ">= 0.5.0"
},
"dependencies": {
"verror": "^1.4.0"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc