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
c93e0aaf06
This patch issues a deprecation message saying the usage of this
interface is deprecated.
PR-URL: https://github.com/nodejs/node/pull/4525
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
This commit is contained in:
parent
c0bfac6ba9
commit
1124de2d76
11
lib/fs.js
11
lib/fs.js
@ -35,6 +35,7 @@ const isWindows = process.platform === 'win32';
|
|||||||
|
|
||||||
const DEBUG = process.env.NODE_DEBUG && /fs/.test(process.env.NODE_DEBUG);
|
const DEBUG = process.env.NODE_DEBUG && /fs/.test(process.env.NODE_DEBUG);
|
||||||
const errnoException = util._errnoException;
|
const errnoException = util._errnoException;
|
||||||
|
const printDeprecation = require('internal/util').printDeprecationMessage;
|
||||||
|
|
||||||
function throwOptionsError(options) {
|
function throwOptionsError(options) {
|
||||||
throw new TypeError('Expected options to be either an object or a string, ' +
|
throw new TypeError('Expected options to be either an object or a string, ' +
|
||||||
@ -584,9 +585,14 @@ fs.openSync = function(path, flags, mode) {
|
|||||||
return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);
|
return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var readWarned = false;
|
||||||
fs.read = function(fd, buffer, offset, length, position, callback) {
|
fs.read = function(fd, buffer, offset, length, position, callback) {
|
||||||
if (!(buffer instanceof Buffer)) {
|
if (!(buffer instanceof Buffer)) {
|
||||||
// legacy string interface (fd, length, position, encoding, callback)
|
// legacy string interface (fd, length, position, encoding, callback)
|
||||||
|
readWarned = printDeprecation('fs.read\'s legacy String interface ' +
|
||||||
|
'is deprecated. Use the Buffer API as ' +
|
||||||
|
'mentioned in the documentation instead.',
|
||||||
|
readWarned);
|
||||||
const cb = arguments[4];
|
const cb = arguments[4];
|
||||||
const encoding = arguments[3];
|
const encoding = arguments[3];
|
||||||
|
|
||||||
@ -636,12 +642,17 @@ function tryToStringWithEnd(buf, encoding, end, callback) {
|
|||||||
callback(e, buf, end);
|
callback(e, buf, end);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var readSyncWarned = false;
|
||||||
fs.readSync = function(fd, buffer, offset, length, position) {
|
fs.readSync = function(fd, buffer, offset, length, position) {
|
||||||
var legacy = false;
|
var legacy = false;
|
||||||
var encoding;
|
var encoding;
|
||||||
|
|
||||||
if (!(buffer instanceof Buffer)) {
|
if (!(buffer instanceof Buffer)) {
|
||||||
// legacy string interface (fd, length, position, encoding, callback)
|
// legacy string interface (fd, length, position, encoding, callback)
|
||||||
|
readSyncWarned = printDeprecation('fs.readSync\'s legacy String interface' +
|
||||||
|
'is deprecated. Use the Buffer API as ' +
|
||||||
|
'mentioned in the documentation instead.',
|
||||||
|
readSyncWarned);
|
||||||
legacy = true;
|
legacy = true;
|
||||||
encoding = arguments[3];
|
encoding = arguments[3];
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user