Fix #547: update Buffer use, docs, tests to match node.js v11.3.0

This commit is contained in:
David Humphrey (:humph) david.humphrey@senecacollege.ca 2018-12-01 19:57:09 -05:00 committed by David Humphrey
parent 9acedc2beb
commit 923b999e89
20 changed files with 139 additions and 123 deletions

View File

@ -213,7 +213,28 @@ When in a node.js environment, native `Buffer`s can be used, or Filer.Buffer, wh
to node's `Buffer`. In a browser, you can use also use `Filer.Buffer`.
NOTE: a `Filer.Buffer` in a browser is really an augmented `Uint8Array` (i.e., the node `Buffer` api
methods are added to the instance). See https://github.com/feross/buffer for more details. Additionally, unlike native `Buffer`, `Filer.Buffer`'s constructor can accept `ArrayBuffer` objects, which will be interpreted as `Uint8Array`s.
methods are added to the instance). See https://github.com/feross/buffer for more details.
NOTE: `Filer.Buffer` currently includes the older, deprecated [constructor functions](https://nodejs.org/api/buffer.html#buffer_new_buffer_array), but these will be removed
at some point. You are encouraged to switch to use the newer class methods `Buffer.from()`
and `Buffer.alloc()`. See the [node.js Buffer docs](https://nodejs.org/api/buffer.html).
```js
/* Deprecated - see https://nodejs.org/api/buffer.html#buffer_new_buffer_array */
new Buffer(array)
new Buffer(arrayBuffer[, byteOffset[, length]])
new Buffer(buffer)
new Buffer(string[, encoding])
new Buffer(size)
/* Use Instead */
Buffer.from(array)
Buffer.from(arrayBuffer[, byteOffset[, length]])
Buffer.from(buffer)
Buffer.from(string[, encoding])
Buffer.alloc(size)
Buffer.allocUnsafe(size)
```
#### Filer.Path<a name="FilerPath"></a>
@ -357,7 +378,7 @@ Example:
```javascript
// Create a file, shrink it, expand it.
var buffer = new Filer.Buffer([1, 2, 3, 4, 5, 6, 7, 8]);
var buffer = Filer.Buffer.from([1, 2, 3, 4, 5, 6, 7, 8]);
fs.open('/myfile', 'w', function(err, fd) {
if(err) throw error;
@ -388,7 +409,7 @@ Example:
```javascript
// Create a file, shrink it, expand it.
var buffer = new Filer.Buffer([1, 2, 3, 4, 5, 6, 7, 8]);
var buffer = Filer.Buffer.from([1, 2, 3, 4, 5, 6, 7, 8]);
fs.open('/myfile', 'w', function(err, fd) {
if(err) throw error;
@ -905,7 +926,7 @@ Example:
```javascript
// Create a file with the following bytes.
var buffer = new Filer.Buffer([1, 2, 3, 4, 5, 6, 7, 8]);
var buffer = Filer.Buffer.from([1, 2, 3, 4, 5, 6, 7, 8]);
fs.open('/myfile', 'w', function(err, fd) {
if(err) throw error;
@ -950,7 +971,7 @@ fs.open('/myfile', 'r', function(err, fd) {
// Create a buffer large enough to hold the file's contents
var nbytes = expected = stats.size;
var buffer = new Filer.Buffer(nbytes);
var buffer = Filer.Buffer.alloc(nbytes);
var read = 0;
function readBytes(offset, position, length) {
@ -1008,7 +1029,7 @@ fs.writeFile('/myfile.txt', "...data...", function (err) {
});
// Write binary file
var buffer = new Filer.Buffer([1, 2, 3, 4, 5, 6, 7, 8]);
var buffer = Filer.Buffer.from([1, 2, 3, 4, 5, 6, 7, 8]);
fs.writeFile('/myfile', buffer, function (err) {
if (err) throw err;
});
@ -1031,8 +1052,8 @@ fs.appendFile('/myfile.txt', "Data...", function (err) {
// '/myfile.txt' would now read out 'More...Data...'
// Append binary file
var data = new Filer.Buffer([1, 2, 3, 4]);
var more = new Filer.Buffer([5, 6, 7, 8]);
var data = Filer.Buffer.from([1, 2, 3, 4]);
var more = Filer.Buffer.from([5, 6, 7, 8]);
fs.writeFile('/myfile', data, function (err) {
if (err) throw err;

View File

@ -1,23 +0,0 @@
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);
}
// 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];
}
});
module.exports = FilerBuffer;

View File

@ -1,13 +1,4 @@
// Adapt encodings to work with Buffer or Uint8Array, they expect the latter
function decode(buf) {
return buf.toString('utf8');
}
function encode(string) {
return new Buffer(string, 'utf8');
}
module.exports = {
encode: encode,
decode: decode
encode: string => Buffer.from(string),
decode: buffer => buffer.toString('utf8')
};

View File

@ -36,7 +36,6 @@ var OpenFileDescription = require('../open-file-description.js');
var SuperNode = require('../super-node.js');
var Node = require('../node.js');
var Stats = require('../stats.js');
var Buffer = require('../buffer.js');
/**
* Update node times. Only passed times are modified (undefined times are ignored)
@ -672,8 +671,7 @@ function open_file(context, path, flags, mode, callback) {
if(error) {
callback(error);
} else {
fileData = new Buffer(0);
fileData.fill(0);
fileData = Buffer.alloc(0);
context.putBuffer(fileNode.data, fileData, update_directory_data);
}
}
@ -738,8 +736,8 @@ function replace_data(context, ofd, buffer, offset, length, callback) {
callback(error);
} else {
fileNode = result;
var newData = new Buffer(length);
newData.fill(0);
var newData = Buffer.alloc(length);
buffer.copy(newData, 0, offset, offset + length);
ofd.position = length;
@ -792,8 +790,7 @@ function write_data(context, ofd, buffer, offset, length, position, callback) {
}
var _position = (!(undefined === position || null === position)) ? position : ofd.position;
var newSize = Math.max(fileData.length, _position + length);
var newData = new Buffer(newSize);
newData.fill(0);
var newData = Buffer.alloc(newSize);
if(fileData) {
fileData.copy(newData);
}
@ -1268,8 +1265,7 @@ function truncate_file(context, path, length, callback) {
if(!fileData) {
return callback(new Errors.EIO('Expected Buffer'));
}
var data = new Buffer(length);
data.fill(0);
var data = Buffer.alloc(length);
if(fileData) {
fileData.copy(data);
}
@ -1328,8 +1324,7 @@ function ftruncate_file(context, ofd, length, callback) {
if(fileData) {
data = fileData.slice(0, length);
} else {
data = new Buffer(length);
data.fill(0);
data = Buffer.alloc(length);
}
context.putBuffer(fileNode.data, data, update_file_node);
}
@ -1802,8 +1797,7 @@ function readFile(fs, context, path, options, callback) {
}
var size = stats.size;
var buffer = new Buffer(size);
buffer.fill(0);
var buffer = Buffer.alloc(size);
read_data(context, ofd, buffer, 0, size, 0, function(err) {
cleanup();

View File

@ -1,6 +1,6 @@
module.exports = {
FileSystem: require('./filesystem/interface.js'),
Buffer: require('./buffer.js'),
Buffer: Buffer,
Path: require('./path.js'),
Errors: require('./errors.js'),
Shell: require('./shell/shell.js')

View File

@ -2,7 +2,6 @@ var FILE_SYSTEM_NAME = require('../constants.js').FILE_SYSTEM_NAME;
var FILE_STORE_NAME = require('../constants.js').FILE_STORE_NAME;
var IDB_RW = require('../constants.js').IDB_RW;
var IDB_RO = require('../constants.js').IDB_RO;
var FilerBuffer = require('../buffer.js');
var indexedDB = global.indexedDB ||
global.mozIndexedDB ||
@ -64,7 +63,7 @@ IndexedDBContext.prototype.getBuffer = function(key, callback) {
if(err) {
return callback(err);
}
callback(null, new FilerBuffer(arrayBuffer));
callback(null, Buffer.from(arrayBuffer));
});
};

View File

@ -4,7 +4,6 @@ var WSQL_VERSION = require('../constants.js').WSQL_VERSION;
var WSQL_SIZE = require('../constants.js').WSQL_SIZE;
var WSQL_DESC = require('../constants.js').WSQL_DESC;
var Errors = require('../errors.js');
var FilerBuffer = require('../buffer.js');
var base64ArrayBuffer = require('base64-arraybuffer');
function WebSQLContext(db, isReadOnly) {
@ -75,7 +74,7 @@ WebSQLContext.prototype.getBuffer = function(key, callback) {
// Deal with zero-length ArrayBuffers, which will be encoded as ''
if(result || result === '') {
var arrayBuffer = base64ArrayBuffer.decode(result);
result = new FilerBuffer(arrayBuffer);
result = Buffer.from(arrayBuffer);
}
callback(null, result);

View File

@ -7,7 +7,7 @@ describe('Filer.Buffer should accept initialized ArrayBuffers, issue 249', funct
afterEach(util.cleanup);
it('should accept an ArrayBuffer with a specified size', function(done) {
var buffer = new Filer.Buffer(new ArrayBuffer(5));
var buffer = Buffer.from(new ArrayBuffer(5));
expect(buffer.length).to.equal(5);
done();
});
@ -18,7 +18,7 @@ describe('Filer.Buffer static methods are in tact, issue 249', function() {
afterEach(util.cleanup);
it('should proxy Buffer.isBuffer', function(done) {
expect(Filer.Buffer.isBuffer(new Filer.Buffer([]))).to.equal(true);
expect(Filer.Buffer.isBuffer(Buffer.from([]))).to.equal(true);
expect(Filer.Buffer.isBuffer('')).to.equal(false);
done();
});
@ -35,7 +35,7 @@ describe('Filer.Buffer static methods are in tact, issue 249', function() {
});
it('should proxy Buffer.concat', function(done) {
expect(Filer.Buffer.concat([new Filer.Buffer(1), new Filer.Buffer(2)]).length).to.equal(3);
expect(Filer.Buffer.concat([Buffer.alloc(1), Buffer.alloc(2)]).length).to.equal(3);
done();
});
});

View File

@ -5,6 +5,7 @@
// Filer
require('./spec/filer.spec');
require('./spec/filer.buffer.spec.js');
// Filer.FileSystem.*
require('./spec/filer.filesystem.spec');

View File

@ -0,0 +1,49 @@
var Filer = require('../../src');
var expect = require('chai').expect;
describe('Filer.Buffer', function() {
it('should support .from()', function() {
expect(Filer.Buffer.from).to.be.a('function');
});
it('should support .alloc()', function() {
expect(Filer.Buffer.alloc).to.be.a('function');
});
it('should support .isBuffer()', function() {
var buf = Buffer.alloc(0);
expect(Buffer.isBuffer(buf)).to.be.true;
});
describe('Deprecation checks - constructor vs. class method init', function() {
it('should allow new Buffer(array)', function() {
var arr = [1, 2, 3];
var buf1 = new Buffer(arr);
var buf2 = new Buffer.from(arr);
expect(buf1).to.deep.equal(buf2);
});
it('should allow new Buffer(ArrayBuffer)', function() {
var arrayBuffer = (new Uint8Array([1, 2, 3])).buffer;
var buf1 = new Buffer(arrayBuffer);
var buf2 = Buffer.from(arrayBuffer);
expect(buf1).to.deep.equal(buf2);
});
it('should allow new Buffer(ArrayBuffer)', function() {
var buffer = new Buffer.from([1, 2, 3]);
var buf1 = new Buffer(buffer);
var buf2 = Buffer.from(buffer);
expect(buf1).to.deep.equal(buf2);
});
it('should allow new Buffer(string)', function() {
var s = 'Hello World';
var buf1 = new Buffer(s);
var buf2 = Buffer.from(s);
expect(buf1).to.deep.equal(buf2);
});
});
});

View File

@ -70,9 +70,9 @@ describe('fs.appendFile', function() {
var fs = util.fs();
// String and utf8 binary encoded versions of the same thing: 'This is a file.'
var binary = new Buffer([84, 104, 105, 115, 32, 105, 115, 32, 97, 32, 102, 105, 108, 101, 46]);
var binary2 = new Buffer([32, 65, 112, 112, 101, 110, 100, 101, 100, 46]);
var binary3 = new Buffer([84, 104, 105, 115, 32, 105, 115, 32, 97, 32, 102, 105, 108, 101, 46,
var binary = Buffer.from([84, 104, 105, 115, 32, 105, 115, 32, 97, 32, 102, 105, 108, 101, 46]);
var binary2 = Buffer.from([32, 65, 112, 112, 101, 110, 100, 101, 100, 46]);
var binary3 = Buffer.from([84, 104, 105, 115, 32, 105, 115, 32, 97, 32, 102, 105, 108, 101, 46,
32, 65, 112, 112, 101, 110, 100, 101, 100, 46]);
fs.writeFile('/mybinaryfile', binary, function(error) {

View File

@ -1,4 +1,3 @@
var Filer = require('../../src');
var util = require('../lib/test-utils.js');
var expect = require('chai').expect;
@ -12,7 +11,7 @@ describe('fs.close', function() {
});
it('should release the file descriptor', function(done) {
var buffer = new Filer.Buffer(0);
var buffer = Buffer.alloc(0);
var fs = util.fs();
fs.open('/myfile', 'w+', function(error, result) {

View File

@ -44,8 +44,8 @@ describe('fs.ftruncate', function() {
it('should truncate a file', function(done) {
let fs = util.fs();
let buffer = new Buffer([1, 2, 3, 4, 5, 6, 7, 8]);
let truncated = new Buffer([1, 2]);
let buffer = Buffer.from([1, 2, 3, 4, 5, 6, 7, 8]);
let truncated = Buffer.from([1, 2]);
fs.open('/myfile', 'w', function(error, result) {
if(error) throw error;
@ -76,7 +76,7 @@ describe('fs.ftruncate', function() {
it('should truncate a valid descriptor', function(done) {
var fs = util.fs();
var buffer = new Buffer([1, 2, 3, 4, 5, 6, 7, 8]);
var buffer = Buffer.from([1, 2, 3, 4, 5, 6, 7, 8]);
fs.open('/myfile', 'w', function(error, result) {
if(error) throw error;
@ -102,8 +102,8 @@ describe('fs.ftruncate', function() {
it('should pad a file with zeros when the length is greater than the file size', function(done) {
let fs = util.fs();
let buffer = new Buffer([1, 2, 3, 4, 5, 6, 7, 8]);
let truncated = new Buffer([1, 2, 3, 4, 5, 6, 7, 8, 0]);
let buffer = Buffer.from([1, 2, 3, 4, 5, 6, 7, 8]);
let truncated = Buffer.from([1, 2, 3, 4, 5, 6, 7, 8, 0]);
fs.open('/myfile', 'w', function(error, result) {
if(error) throw error;
@ -133,7 +133,7 @@ describe('fs.ftruncate', function() {
it('should assume a length of 0 if passed undefined', function(done) {
var fs = util.fs();
var buffer = new Buffer([1, 2, 3, 4, 5, 6, 7, 8]);
var buffer = Buffer.from([1, 2, 3, 4, 5, 6, 7, 8]);
fs.open('/myfile', 'w', function(error, result) {
if(error) throw error;
@ -163,7 +163,7 @@ describe('fs.ftruncate', function() {
it('should update the file size', function(done) {
var fs = util.fs();
var buffer = new Buffer([1, 2, 3, 4, 5, 6, 7, 8]);
var buffer = Buffer.from([1, 2, 3, 4, 5, 6, 7, 8]);
fs.open('/myfile', 'w', function(error, result) {
if(error) throw error;

View File

@ -1,4 +1,3 @@
var Filer = require('../../src');
var util = require('../lib/test-utils.js');
var expect = require('chai').expect;
@ -50,9 +49,8 @@ describe('fs.lseek', function() {
it('should set the current position if whence is SET', function(done) {
var fs = util.fs();
var offset = 3;
var buffer = new Filer.Buffer([1, 2, 3, 4, 5, 6, 7, 8]);
var result_buffer = new Filer.Buffer(buffer.length + offset);
result_buffer.fill(0);
var buffer = Buffer.from([1, 2, 3, 4, 5, 6, 7, 8]);
var result_buffer = Buffer.alloc(buffer.length + offset);
fs.open('/myfile', 'w+', function(error, fd) {
if(error) throw error;
@ -77,7 +75,7 @@ describe('fs.lseek', function() {
if(error) throw error;
expect(result.size).to.equal(offset + buffer.length);
var expected = new Filer.Buffer([1, 2, 3, 1, 2, 3, 4, 5, 6, 7, 8]);
var expected = Buffer.from([1, 2, 3, 1, 2, 3, 4, 5, 6, 7, 8]);
expect(result_buffer).to.deep.equal(expected);
done();
});
@ -91,9 +89,8 @@ describe('fs.lseek', function() {
it('should update the current position if whence is CUR', function(done) {
var fs = util.fs();
var offset = -2;
var buffer = new Filer.Buffer([1, 2, 3, 4, 5, 6, 7, 8]);
var result_buffer = new Filer.Buffer(2 * buffer.length + offset);
result_buffer.fill(0);
var buffer = Buffer.from([1, 2, 3, 4, 5, 6, 7, 8]);
var result_buffer = Buffer.alloc(2 * buffer.length + offset);
fs.open('/myfile', 'w+', function(error, fd) {
if(error) throw error;
@ -118,7 +115,7 @@ describe('fs.lseek', function() {
if(error) throw error;
expect(result.size).to.equal(offset + 2 * buffer.length);
var expected = new Filer.Buffer([1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 7, 8]);
var expected = Buffer.from([1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 7, 8]);
expect(result_buffer).to.deep.equal(expected);
done();
});
@ -132,7 +129,7 @@ describe('fs.lseek', function() {
it('should update the current position if whence is END', function(done) {
var fs = util.fs();
var offset = 5;
var buffer = new Filer.Buffer([1, 2, 3, 4, 5, 6, 7, 8]);
var buffer = Buffer.from([1, 2, 3, 4, 5, 6, 7, 8]);
var result_buffer;
fs.open('/myfile', 'w+', function(error, result) {
@ -159,13 +156,12 @@ describe('fs.lseek', function() {
if(error) throw error;
expect(result.size).to.equal(offset + 2 * buffer.length);
result_buffer = new Filer.Buffer(result.size);
result_buffer.fill(0);
result_buffer = Buffer.alloc(result.size);
fs.read(fd2, result_buffer, 0, result_buffer.length, 0, function(error, result) {
if(error) throw error;
expect(result).to.equal(result_buffer.length);
var expected = new Filer.Buffer([1, 2, 3, 4, 5, 6, 7, 8, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8]);
var expected = Buffer.from([1, 2, 3, 4, 5, 6, 7, 8, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8]);
expect(result_buffer).to.deep.equal(expected);
done();
});

View File

@ -1,4 +1,3 @@
var Filer = require('../../src');
var util = require('../lib/test-utils.js');
var expect = require('chai').expect;
@ -13,9 +12,8 @@ describe('fs.read', function() {
it('should read data from a file', function(done) {
var fs = util.fs();
var wbuffer = new Filer.Buffer([1, 2, 3, 4, 5, 6, 7, 8]);
var rbuffer = new Filer.Buffer(wbuffer.length);
rbuffer.fill(0);
var wbuffer = Buffer.from([1, 2, 3, 4, 5, 6, 7, 8]);
var rbuffer = Buffer.alloc(wbuffer.length);
fs.open('/myfile', 'w+', function(error, fd) {
if(error) throw error;
@ -35,9 +33,8 @@ describe('fs.read', function() {
it('should update the current file position', function(done) {
var fs = util.fs();
var wbuffer = new Filer.Buffer([1, 2, 3, 4, 5, 6, 7, 8]);
var rbuffer = new Filer.Buffer(wbuffer.length);
rbuffer.fill(0);
var wbuffer = Buffer.from([1, 2, 3, 4, 5, 6, 7, 8]);
var rbuffer = Buffer.alloc(wbuffer.length);
var _result = 0;
fs.open('/myfile', 'w+', function(error, fd) {
@ -66,10 +63,8 @@ describe('fs.read', function() {
it('should fail to read a directory', function(done) {
var fs = util.fs();
var buf = new Filer.Buffer(20);
var buf2 = new Filer.Buffer(20);
buf.fill(0);
buf2.fill(0);
var buf = Buffer.alloc(20);
var buf2 = Buffer.alloc(20);
fs.mkdir('/mydir', function(error) {
if(error) throw error;
@ -92,8 +87,7 @@ describe('fs.read', function() {
var fs = util.fs();
var fd = 0;
var rbuffer = new Filer.Buffer(8);
rbuffer.fill(0);
var rbuffer = Buffer.alloc(8);
fs.read(fd, rbuffer, 0, rbuffer.length, 0, function(error, result) {
expect(error).to.exist;

View File

@ -52,8 +52,8 @@ describe('fs.truncate', function() {
it('should truncate a file', function(done) {
var fs = util.fs();
var buffer = new Buffer([1, 2, 3, 4, 5, 6, 7, 8]);
var truncated = new Buffer([1]);
var buffer = Buffer.from([1, 2, 3, 4, 5, 6, 7, 8]);
var truncated = Buffer.from([1]);
fs.open('/myfile', 'w', function(error, result) {
if(error) throw error;
@ -83,8 +83,8 @@ describe('fs.truncate', function() {
it('should pad a file with zeros when the length is greater than the file size', function(done) {
var fs = util.fs();
var buffer = new Buffer([1, 2, 3, 4, 5, 6, 7, 8]);
var truncated = new Buffer([1, 2, 3, 4, 5, 6, 7, 8, 0]);
var buffer = Buffer.from([1, 2, 3, 4, 5, 6, 7, 8]);
var truncated = Buffer.from([1, 2, 3, 4, 5, 6, 7, 8, 0]);
fs.open('/myfile', 'w', function(error, result) {
if(error) throw error;
@ -114,7 +114,7 @@ describe('fs.truncate', function() {
it('should update the file size', function(done) {
var fs = util.fs();
var buffer = new Buffer([1, 2, 3, 4, 5, 6, 7, 8]);
var buffer = Buffer.from([1, 2, 3, 4, 5, 6, 7, 8]);
fs.open('/myfile', 'w', function(error, result) {
if(error) throw error;
@ -144,7 +144,7 @@ describe('fs.truncate', function() {
it('should assume a length of 0 if passed undefined', function(done) {
var fs = util.fs();
var buffer = new Buffer([1, 2, 3, 4, 5, 6, 7, 8]);
var buffer = Buffer.from([1, 2, 3, 4, 5, 6, 7, 8]);
fs.open('/myfile', 'w', function(error, result) {
if(error) throw error;
@ -175,7 +175,7 @@ describe('fs.truncate', function() {
it('should follow symbolic links', function(done) {
var fs = util.fs();
var buffer = new Buffer([1, 2, 3, 4, 5, 6, 7, 8]);
var buffer = Buffer.from([1, 2, 3, 4, 5, 6, 7, 8]);
fs.open('/myfile', 'w', function(error, result) {
if(error) throw error;

View File

@ -1,4 +1,3 @@
var Filer = require('../../src');
var util = require('../lib/test-utils.js');
var expect = require('chai').expect;
@ -13,7 +12,7 @@ describe('fs.write', function() {
it('should write data to a file', function(done) {
var fs = util.fs();
var buffer = new Filer.Buffer([1, 2, 3, 4, 5, 6, 7, 8]);
var buffer = Buffer.from([1, 2, 3, 4, 5, 6, 7, 8]);
fs.open('/myfile', 'w', function(error, fd) {
if(error) throw error;
@ -34,7 +33,7 @@ describe('fs.write', function() {
it('should update the current file position', function(done) {
var fs = util.fs();
var buffer = new Filer.Buffer([1, 2, 3, 4, 5, 6, 7, 8]);
var buffer = Buffer.from([1, 2, 3, 4, 5, 6, 7, 8]);
var _result = 0;
fs.open('/myfile', 'w', function(error, fd) {

View File

@ -80,7 +80,7 @@ describe('fs.writeFile, fs.readFile', function() {
it('should write, read a binary file', function(done) {
var fs = util.fs();
// String and utf8 binary encoded versions of the same thing: 'This is a file.'
var binary = new Buffer([84, 104, 105, 115, 32, 105, 115, 32, 97, 32, 102, 105, 108, 101, 46]);
var binary = Buffer.from([84, 104, 105, 115, 32, 105, 115, 32, 97, 32, 102, 105, 108, 101, 46]);
fs.writeFile('/myfile', binary, function(error) {
if(error) throw error;
@ -180,7 +180,7 @@ describe('fsPromises.writeFile, fsPromises.readFile', function() {
it('should write, read a binary file', function() {
var fsPromises = util.fs().promises;
// String and utf8 binary encoded versions of the same thing: 'This is a file.'
var binary = new Buffer([84, 104, 105, 115, 32, 105, 115, 32, 97, 32, 102, 105, 108, 101, 46]);
var binary = Buffer.from([84, 104, 105, 115, 32, 105, 115, 32, 97, 32, 102, 105, 108, 101, 46]);
return fsPromises.writeFile('/myfile', binary)
.then( () => fsPromises.readFile('/myfile'))

View File

@ -1,6 +1,5 @@
/* eslint no-console: 0 */
var Buffer = require('../../../src').Buffer;
var util = require('../../lib/test-utils.js');
var expect = require('chai').expect;
@ -77,8 +76,7 @@ module.exports = function createProviderTestsFor(providerName, testProvider) {
if(error) throw error;
var context = provider.getReadWriteContext();
// Filer Buffer
var buf = new Buffer([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
var buf = Buffer.from([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
context.putBuffer('key', buf, function(error) {
if(error) throw error;
@ -97,8 +95,8 @@ module.exports = function createProviderTestsFor(providerName, testProvider) {
if(error) throw error;
var context = provider.getReadWriteContext();
// Zero-length Filer Buffer
var buf = new Buffer(new ArrayBuffer(0));
// Zero-length Buffer
var buf = Buffer.alloc(0);
context.putBuffer('key', buf, function(error) {
if(error) throw error;

View File

@ -1,4 +1,3 @@
var Filer = require('../../src');
var util = require('../lib/test-utils.js');
var expect = require('chai').expect;
@ -355,7 +354,7 @@ describe('node times (atime, mtime, ctime)', function() {
it('should update atime, ctime, mtime when calling fs.write()', function(done) {
var fs = util.fs();
var buffer = new Filer.Buffer([1, 2, 3, 4, 5, 6, 7, 8]);
var buffer = Buffer.from([1, 2, 3, 4, 5, 6, 7, 8]);
createTree(function() {
fs.open('/myfile', 'w', function(error, fd) {
@ -384,7 +383,7 @@ describe('node times (atime, mtime, ctime)', function() {
it('should make no change when calling fs.read()', function(done) {
var fs = util.fs();
var buffer = new Filer.Buffer([1, 2, 3, 4, 5, 6, 7, 8]);
var buffer = Buffer.from([1, 2, 3, 4, 5, 6, 7, 8]);
createTree(function() {
fs.open('/myfile', 'w', function(err, fd) {
@ -401,8 +400,8 @@ describe('node times (atime, mtime, ctime)', function() {
if(error) throw error;
stat('/myfile', function(stats1) {
var buffer2 = new Filer.Buffer(buffer.length);
buffer2.fill(0);
var buffer2 = Buffer.alloc(buffer.length);
fs.read(fd, buffer2, 0, buffer2.length, 0, function(err, nbytes) {
if(err) throw err;
expect(nbytes).to.equal(buffer2.length);