Skip to content

Commit deb15fc

Browse files
committed
fs: deprecate fs.read's string interface
`fs.read` supports a deprecated string interface version, which is not documented. It was intended to be deprecated in this commit in 2010 c93e0aa This patch issues a deprecation message saying the usage of this interface is deprecated.
1 parent 4644673 commit deb15fc

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

lib/fs.js

+11
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ const isWindows = process.platform === 'win32';
3535

3636
const DEBUG = process.env.NODE_DEBUG && /fs/.test(process.env.NODE_DEBUG);
3737
const errnoException = util._errnoException;
38+
const printDeprecation = require('internal/util').printDeprecationMessage;
3839

3940
function throwOptionsError(options) {
4041
throw new TypeError('Expected options to be either an object or a string, ' +
@@ -584,9 +585,14 @@ fs.openSync = function(path, flags, mode) {
584585
return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);
585586
};
586587

588+
var readWarned = false;
587589
fs.read = function(fd, buffer, offset, length, position, callback) {
588590
if (!(buffer instanceof Buffer)) {
589591
// legacy string interface (fd, length, position, encoding, callback)
592+
readWarned = printDeprecation('fs.read\'s legacy String interface ' +
593+
'is deprecated. Use the Buffer API as ' +
594+
'mentioned in the documentation instead.',
595+
readWarned);
590596
const cb = arguments[4];
591597
const encoding = arguments[3];
592598

@@ -636,12 +642,17 @@ function tryToStringWithEnd(buf, encoding, end, callback) {
636642
callback(e, buf, end);
637643
}
638644

645+
var readSyncWarned = false;
639646
fs.readSync = function(fd, buffer, offset, length, position) {
640647
var legacy = false;
641648
var encoding;
642649

643650
if (!(buffer instanceof Buffer)) {
644651
// legacy string interface (fd, length, position, encoding, callback)
652+
readSyncWarned = printDeprecation('fs.readSync\'s legacy String interface' +
653+
'is deprecated. Use the Buffer API as ' +
654+
'mentioned in the documentation instead.',
655+
readSyncWarned);
645656
legacy = true;
646657
encoding = arguments[3];
647658

0 commit comments

Comments
 (0)