add some needed monkey patches
This commit is contained in:
parent
021d51b059
commit
c9ab03312a
|
@ -0,0 +1,16 @@
|
|||
exports.patch = function(Buffers) {
|
||||
Buffers.prototype.skip = function (i) {
|
||||
if (i == 0) {
|
||||
return;
|
||||
} else if (i == this.length) {
|
||||
this.buffers = [];
|
||||
this.length = 0;
|
||||
return;
|
||||
}
|
||||
var pos = this.pos(i);
|
||||
this.buffers = this.buffers.slice(pos.buf);
|
||||
this.buffers[0].length -= pos.offset;
|
||||
this.buffers[0].offset += pos.offset;
|
||||
this.length -= i;
|
||||
};
|
||||
};
|
|
@ -11,6 +11,7 @@ function spec(b) {
|
|||
var Binary = b.Binary || require('binary');
|
||||
var Put = b.Put || require('bufferput');
|
||||
var Buffers = b.Buffers || require('buffers');
|
||||
require('./Buffers.monkey').patch(Buffers);
|
||||
var noop = function() {};
|
||||
var util = b.util || require('./util/util');
|
||||
var Parser = b.Parser || require('./util/BinaryParser').class();
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
exports.patch = function(Number) {
|
||||
//round to specified number of places
|
||||
Number.prototype.round = function(places) {
|
||||
if(!places) return Math.round(this);
|
||||
var tmp = Math.pow(10,places);
|
||||
return Math.round(this * tmp) / tmp;
|
||||
};
|
||||
};
|
Loading…
Reference in New Issue