From c9ab03312a474d07c1512b6d09a478643b5e1f48 Mon Sep 17 00:00:00 2001 From: Stephen Pair Date: Thu, 18 Jul 2013 12:01:12 -0400 Subject: [PATCH] add some needed monkey patches --- Buffers.monkey.js | 16 ++++++++++++++++ Connection.js | 1 + Number.monkey.js | 8 ++++++++ 3 files changed, 25 insertions(+) create mode 100644 Buffers.monkey.js create mode 100644 Number.monkey.js diff --git a/Buffers.monkey.js b/Buffers.monkey.js new file mode 100644 index 0000000..ef7c73d --- /dev/null +++ b/Buffers.monkey.js @@ -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; + }; +}; diff --git a/Connection.js b/Connection.js index 1d0863d..e54a8ec 100644 --- a/Connection.js +++ b/Connection.js @@ -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(); diff --git a/Number.monkey.js b/Number.monkey.js new file mode 100644 index 0000000..f1d906c --- /dev/null +++ b/Number.monkey.js @@ -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; + }; +};