[Issue249] Support for ArrayBuffer in Filer.Buffer

1. Added proxy Buffer constructor for Filer.Buffer.
2. Added tests for new Filer.Buffer.
This commit is contained in:
secretrobotron 2014-08-08 15:18:09 -04:00
parent 4b01276c28
commit af1943b5c9
3 changed files with 33 additions and 0 deletions

18
src/buffer.js Normal file
View File

@ -0,0 +1,18 @@
function FilerBuffer (subject, encoding, nonZero) {
// Automatically turn ArrayBuffer into Uint8Array so that underlying
// Buffer code doesn't just throw away and ignore ArrayBuffer data.
if (subject instanceof ArrayBuffer) {
subject = new Uint8Array(subject);
}
return new Buffer(subject, encoding, nonZero);
};
Object.keys(Buffer).forEach(function (p) {
if (Buffer.hasOwnProperty(p)) {
FilerBuffer[p] = Buffer[p];
}
});
module.exports = FilerBuffer;

14
tests/bugs/issue249.js Normal file
View File

@ -0,0 +1,14 @@
var Filer = require('../..');
var util = require('../lib/test-utils.js');
var expect = require('chai').expect;
describe('Filer.Buffer should accept initialized ArrayBuffers, issue 249', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
it('should accept an ArrayBuffer with a specified size', function(done) {
var buffer = new Filer.Buffer(new ArrayBuffer(5));
expect(buffer.length).to.equal(5);
done();
});
});

View File

@ -68,5 +68,6 @@ require("./spec/node-js/simple/test-fs-watch-recursive");
require("./bugs/issue105");
require("./bugs/issue106");
require("./bugs/issue239");
require("./bugs/issue249");
require("./bugs/ls-depth-bug");
require("./bugs/issue247.js");