Skip to content

Commit

Permalink
fs: use process.emitWarning to print deprecation warning
Browse files Browse the repository at this point in the history
As an alternative to nodejs#6413, use
process.emitWarning() instead of the internal printDeprecationMessage
in order to avoid use of an internal only API.
  • Loading branch information
jasnell committed Sep 2, 2016
1 parent 5aa3ea2 commit 09d97e9
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ const isWindows = process.platform === 'win32';

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

function throwOptionsError(options) {
throw new TypeError('Expected options to be either an object or a string, ' +
Expand Down Expand Up @@ -613,10 +612,14 @@ var readWarned = false;
fs.read = function(fd, buffer, offset, length, position, callback) {
if (!(buffer instanceof Buffer)) {
// 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);
if (!readWarned) {
readWarned = true;
process.emitWarning(
'fs.read\'s legacy String interface is deprecated. Use the Buffer ' +
'API as mentioned in the documentation instead.',
'DeprecationWarning');
}

const cb = arguments[4];
const encoding = arguments[3];

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

if (!(buffer instanceof Buffer)) {
// 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);
if (!readSyncWarned) {
readSyncWarned = true;
process.emitWarning(
'fs.readSync\'s legacy String interface is deprecated. Use the ' +
'Buffer API as mentioned in the documentation instead.',
'DeprecationWarning');
}
legacy = true;
encoding = arguments[3];

Expand Down

0 comments on commit 09d97e9

Please sign in to comment.