Skip to content
This repository was archived by the owner on Aug 15, 2024. It is now read-only.

Avoid using deprecated Buffer constructor #62

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/MemoryFileSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ class MemoryFileSystem {
if(isDir(current[path[i]]))
throw new MemoryFileSystemError(errors.code.EISDIR, _path, "writeFile");
const encoding = typeof optionsOrEncoding === "object" ? optionsOrEncoding.encoding : optionsOrEncoding;
current[path[i]] = optionsOrEncoding || typeof content === "string" ? new Buffer(content, encoding) : content;
current[path[i]] = optionsOrEncoding || typeof content === "string" ? Buffer.from(content, encoding) : content;
return;
}

Expand Down Expand Up @@ -254,7 +254,7 @@ class MemoryFileSystem {
let stream = new WritableStream();
try {
// Zero the file and make sure it is writable
this.writeFileSync(path, new Buffer(0));
this.writeFileSync(path, Buffer.alloc(0));
} catch(e) {
// This or setImmediate?
stream.once('prefinish', function() {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"travis": "npm run cover -- --report lcovonly && npm run lint"
},
"engines": {
"node": ">=4.3.0 <5.0.0 || >=5.10"
"node": ">=4.5.0 <5.0.0 || >=5.10"
},
"repository": {
"type": "git",
Expand Down
14 changes: 7 additions & 7 deletions test/MemoryFileSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ describe("files", function() {
it("should make and remove files", function() {
var fs = new MemoryFileSystem();
fs.mkdirSync("/test");
var buf = new Buffer("Hello World", "utf-8");
var buf = Buffer.from("Hello World", "utf-8");
fs.writeFileSync("/test/hello-world.txt", buf);
fs.readFileSync("/test/hello-world.txt").should.be.eql(buf);
fs.readFileSync("/test/hello-world.txt", "utf-8").should.be.eql("Hello World");
Expand Down Expand Up @@ -242,7 +242,7 @@ describe("async", function() {
content.should.be.eql("Hello");
fs.readFile("/test/dir/b", function(err, content) {
if(err) throw err;
content.should.be.eql(new Buffer("World"));
content.should.be.eql(Buffer.from("World"));
fs.exists("/test/dir/b", function(exists) {
exists.should.be.eql(true);
done();
Expand Down Expand Up @@ -279,7 +279,7 @@ describe("streams", function() {
it("should accept pipes", function(done) {
// TODO: Any way to avoid the asyncness of this?
var fs = new MemoryFileSystem();
bl(new Buffer("Hello"))
bl(Buffer.from("Hello"))
.pipe(fs.createWriteStream("/file"))
.once('finish', function() {
fs.readFileSync("/file", "utf8").should.be.eql("Hello");
Expand Down Expand Up @@ -417,20 +417,20 @@ describe("os", function() {
"": true,
a: {
"": true,
index: new Buffer("1"), // /a/index
index: Buffer.from("1"), // /a/index
dir: {
"": true,
index: new Buffer("2") // /a/dir/index
index: Buffer.from("2") // /a/dir/index
}
},
"C:": {
"": true,
a: {
"": true,
index: new Buffer("3"), // C:\files\index
index: Buffer.from("3"), // C:\files\index
dir: {
"": true,
index: new Buffer("4") // C:\files\a\index
index: Buffer.from("4") // C:\files\a\index
}
}
}
Expand Down