mirror of
https://github.com/nodejs/node.git
synced 2025-05-07 15:35:41 +00:00
fs: use process.emitWarning to print deprecation warning
Use process.emitWarning() instead of the internal printDeprecationMessage in order to avoid use of an internal only API. PR-URL: https://github.com/nodejs/node/pull/8166 Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com> Reviewed-By: Myles Borins <myles.borins@gmail.com>
This commit is contained in:
parent
15eaba98a1
commit
b50557b51b
24
lib/fs.js
24
lib/fs.js
@ -43,7 +43,6 @@ 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, ' +
|
||||||
@ -613,10 +612,14 @@ 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 ' +
|
if (!readWarned) {
|
||||||
'is deprecated. Use the Buffer API as ' +
|
readWarned = true;
|
||||||
'mentioned in the documentation instead.',
|
process.emitWarning(
|
||||||
readWarned);
|
'fs.read\'s legacy String interface is deprecated. Use the Buffer ' +
|
||||||
|
'API as mentioned in the documentation instead.',
|
||||||
|
'DeprecationWarning');
|
||||||
|
}
|
||||||
|
|
||||||
const cb = arguments[4];
|
const cb = arguments[4];
|
||||||
const encoding = arguments[3];
|
const encoding = arguments[3];
|
||||||
|
|
||||||
@ -673,10 +676,13 @@ fs.readSync = function(fd, buffer, offset, length, position) {
|
|||||||
|
|
||||||
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' +
|
if (!readSyncWarned) {
|
||||||
'is deprecated. Use the Buffer API as ' +
|
readSyncWarned = true;
|
||||||
'mentioned in the documentation instead.',
|
process.emitWarning(
|
||||||
readSyncWarned);
|
'fs.readSync\'s legacy String interface is deprecated. Use the ' +
|
||||||
|
'Buffer API as mentioned in the documentation instead.',
|
||||||
|
'DeprecationWarning');
|
||||||
|
}
|
||||||
legacy = true;
|
legacy = true;
|
||||||
encoding = arguments[3];
|
encoding = arguments[3];
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user