fs: remove fs.read's string interface · nodejs/node@3c2a936 · GitHub
Skip to content

Commit 3c2a936

Browse files
authored
fs: remove fs.read's string interface
It is a maintenance burden that was removed from the docs in 2010 (c93e0aa) and runtime-deprecated in v6.0 (1124de2). PR-URL: #9683 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
1 parent 2685464 commit 3c2a936

7 files changed

Lines changed: 57 additions & 218 deletions

lib/fs.js

Lines changed: 2 additions & 80 deletions

test/parallel/test-fs-read-buffer-tostring-fail.js

Lines changed: 0 additions & 64 deletions
This file was deleted.

test/parallel/test-fs-read-buffer-zero-length.js

Lines changed: 0 additions & 19 deletions
This file was deleted.

test/parallel/test-fs-read-buffer.js

Lines changed: 0 additions & 35 deletions
This file was deleted.

test/parallel/test-fs-read-type.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
'use strict';
2+
const common = require('../common');
3+
const assert = require('assert');
4+
const path = require('path');
5+
const fs = require('fs');
6+
const filepath = path.join(common.fixturesDir, 'x.txt');
7+
const fd = fs.openSync(filepath, 'r');
8+
const expected = 'xyz\n';
9+
10+
// Error must be thrown with string
11+
assert.throws(() => {
12+
fs.read(fd,
13+
expected.length,
14+
0,
15+
'utf-8',
16+
() => {});
17+
}, /Second argument needs to be a buffer/);
18+
19+
assert.throws(() => {
20+
fs.readSync(fd, expected.length, 0, 'utf-8');
21+
}, /Second argument needs to be a buffer/);

test/parallel/test-fs-read-zero-length.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,18 @@
22
const common = require('../common');
33
const assert = require('assert');
44
const path = require('path');
5+
const Buffer = require('buffer').Buffer;
56
const fs = require('fs');
67
const filepath = path.join(common.fixturesDir, 'x.txt');
78
const fd = fs.openSync(filepath, 'r');
8-
const expected = '';
9+
const bufferAsync = Buffer.alloc(0);
10+
const bufferSync = Buffer.alloc(0);
911

10-
fs.read(fd, 0, 0, 'utf-8', common.mustCall(function(err, str, bytesRead) {
11-
assert.ok(!err);
12-
assert.equal(str, expected);
12+
fs.read(fd, bufferAsync, 0, 0, 0, common.mustCall(function(err, bytesRead) {
1313
assert.equal(bytesRead, 0);
14+
assert.deepStrictEqual(bufferAsync, Buffer.alloc(0));
1415
}));
1516

16-
const r = fs.readSync(fd, 0, 0, 'utf-8');
17-
assert.equal(r[0], expected);
18-
assert.equal(r[1], 0);
17+
const r = fs.readSync(fd, bufferSync, 0, 0, 0);
18+
assert.deepStrictEqual(bufferSync, Buffer.alloc(0));
19+
assert.equal(r, 0);

test/parallel/test-fs-read.js

Lines changed: 26 additions & 13 deletions

0 commit comments

Comments
 (0)