File: fix-buffer-usage.patch

package info (click to toggle)
node-memory-fs 0.5.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 264 kB
  • sloc: javascript: 940; makefile: 2
file content (79 lines) | stat: -rw-r--r-- 2,765 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
Description: fix Buffer() usage
Author: Xavier Guimard <yadd@debian.org>
Forwarded: no
Last-Update: 2020-12-26

--- a/lib/MemoryFileSystem.js
+++ b/lib/MemoryFileSystem.js
@@ -214,7 +214,7 @@
 		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" ? new Buffer.from(content, encoding) : content;
 		return;
 	}
 
@@ -254,7 +254,7 @@
 		let stream = new WritableStream();
 		try {
 			// Zero the file and make sure it is writable
-			this.writeFileSync(path, new Buffer(0));
+			this.writeFileSync(path, new Buffer.alloc(0));
 		} catch(e) {
 			// This or setImmediate?
 			stream.once('prefinish', function() {
--- a/test/MemoryFileSystem.js
+++ b/test/MemoryFileSystem.js
@@ -77,7 +77,7 @@
 	it("should make and remove files", function() {
 		var fs = new MemoryFileSystem();
 		fs.mkdirSync("/test");
-		var buf = new Buffer("Hello World", "utf-8");
+		var buf = new 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");
@@ -242,7 +242,7 @@
 						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(new Buffer.from("World"));
 							fs.exists("/test/dir/b", function(exists) {
 								exists.should.be.eql(true);
 								done();
@@ -279,7 +279,7 @@
 		it("should accept pipes", function(done) {
 			// TODO: Any way to avoid the asyncness of this?
 			var fs = new MemoryFileSystem();
-			bl(new Buffer("Hello"))
+			bl(new Buffer.from("Hello"))
 				.pipe(fs.createWriteStream("/file"))
 				.once('finish', function() {
 					fs.readFileSync("/file", "utf8").should.be.eql("Hello");
@@ -422,20 +422,20 @@
 			"": true,
 			a: {
 				"": true,
-				index: new Buffer("1"), // /a/index
+				index: new Buffer.from("1"), // /a/index
 				dir: {
 					"": true,
-					index: new Buffer("2") // /a/dir/index
+					index: new Buffer.from("2") // /a/dir/index
 				}
 			},
 			"C:": {
 				"": true,
 				a: {
 					"": true,
-					index: new Buffer("3"),  // C:\files\index
+					index: new Buffer.from("3"),  // C:\files\index
 					dir: {
 						"": true,
-						index: new Buffer("4")  // C:\files\a\index
+						index: new Buffer.from("4")  // C:\files\a\index
 					}
 				}
 			}