From 77e0ee7117064c81dfe54d3eb46c0bec38d74073 Mon Sep 17 00:00:00 2001 From: secretrobotron Date: Sat, 9 Aug 2014 13:05:15 -0400 Subject: [PATCH] [issue249] fixed Buffer prototype & tests --- src/buffer.js | 5 +++++ tests/bugs/issue249.js | 28 ++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/src/buffer.js b/src/buffer.js index 1756aee..bf8745e 100644 --- a/src/buffer.js +++ b/src/buffer.js @@ -9,6 +9,11 @@ function FilerBuffer (subject, encoding, nonZero) { return new Buffer(subject, encoding, nonZero); }; +// Inherit prototype from Buffer +FilerBuffer.prototype = Object.create(Buffer.prototype); +FilerBuffer.prototype.constructor = FilerBuffer; + +// Also copy static methods onto FilerBuffer ctor Object.keys(Buffer).forEach(function (p) { if (Buffer.hasOwnProperty(p)) { FilerBuffer[p] = Buffer[p]; diff --git a/tests/bugs/issue249.js b/tests/bugs/issue249.js index 28776d4..cdb2d3a 100644 --- a/tests/bugs/issue249.js +++ b/tests/bugs/issue249.js @@ -12,3 +12,31 @@ describe('Filer.Buffer should accept initialized ArrayBuffers, issue 249', funct done(); }); }); + +describe('Filer.Buffer static methods are in tact, issue 249', function() { + beforeEach(util.setup); + afterEach(util.cleanup); + + it('should proxy Buffer.isBuffer', function(done) { + expect(Filer.Buffer.isBuffer(new Filer.Buffer([]))).to.equal(true); + expect(Filer.Buffer.isBuffer('')).to.equal(false); + done(); + }); + + it('should proxy Buffer.isEncoding', function(done) { + expect(Filer.Buffer.isEncoding('utf8')).to.equal(true); + expect(Filer.Buffer.isEncoding('smoop')).to.equal(false); + done(); + }); + + it('should proxy Buffer.byteLength', function(done) { + expect(Filer.Buffer.byteLength('01100111', 'binary')).to.equal(8); + done(); + }); + + it('should proxy Buffer.concat', function(done) { + expect(Filer.Buffer.concat([new Filer.Buffer(1), new Filer.Buffer(2)]).length).to.equal(3); + done(); + }); +}); +