From b50557b51b3a2296b94fe1566e88d56fa2f44ebc Mon Sep 17 00:00:00 2001 From: James M Snell Date: Thu, 18 Aug 2016 11:59:24 -0700 Subject: [PATCH] fs: use process.emitWarning to print deprecation warning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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: Сковорода Никита Андреевич Reviewed-By: Myles Borins --- lib/fs.js | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/lib/fs.js b/lib/fs.js index f6059ad65c2a04..6e28a41118e131 100644 --- a/lib/fs.js +++ b/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 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, ' + @@ -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]; @@ -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];