Skip to content

Commit b50557b

Browse files
committed
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: #8166 Reviewed-By: Сковорода Никита Андреевич <[email protected]> Reviewed-By: Myles Borins <[email protected]>
1 parent 15eaba9 commit b50557b

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

lib/fs.js

+15-9
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ const isWindows = process.platform === 'win32';
4343

4444
const DEBUG = process.env.NODE_DEBUG && /fs/.test(process.env.NODE_DEBUG);
4545
const errnoException = util._errnoException;
46-
const printDeprecation = require('internal/util').printDeprecationMessage;
4746

4847
function throwOptionsError(options) {
4948
throw new TypeError('Expected options to be either an object or a string, ' +
@@ -613,10 +612,14 @@ var readWarned = false;
613612
fs.read = function(fd, buffer, offset, length, position, callback) {
614613
if (!(buffer instanceof Buffer)) {
615614
// legacy string interface (fd, length, position, encoding, callback)
616-
readWarned = printDeprecation('fs.read\'s legacy String interface ' +
617-
'is deprecated. Use the Buffer API as ' +
618-
'mentioned in the documentation instead.',
619-
readWarned);
615+
if (!readWarned) {
616+
readWarned = true;
617+
process.emitWarning(
618+
'fs.read\'s legacy String interface is deprecated. Use the Buffer ' +
619+
'API as mentioned in the documentation instead.',
620+
'DeprecationWarning');
621+
}
622+
620623
const cb = arguments[4];
621624
const encoding = arguments[3];
622625

@@ -673,10 +676,13 @@ fs.readSync = function(fd, buffer, offset, length, position) {
673676

674677
if (!(buffer instanceof Buffer)) {
675678
// legacy string interface (fd, length, position, encoding, callback)
676-
readSyncWarned = printDeprecation('fs.readSync\'s legacy String interface' +
677-
'is deprecated. Use the Buffer API as ' +
678-
'mentioned in the documentation instead.',
679-
readSyncWarned);
679+
if (!readSyncWarned) {
680+
readSyncWarned = true;
681+
process.emitWarning(
682+
'fs.readSync\'s legacy String interface is deprecated. Use the ' +
683+
'Buffer API as mentioned in the documentation instead.',
684+
'DeprecationWarning');
685+
}
680686
legacy = true;
681687
encoding = arguments[3];
682688

0 commit comments

Comments
 (0)