From 348d12b1a634f074fac145bf199325b3f446ca2a Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Sat, 6 Oct 2018 18:24:08 -0700 Subject: [PATCH 1/2] zlib: move `bytesRead` accessors to runtime deprecation This paves way for making `bytesRead` consistent with all other Node.js streams that provide a property with this name. --- doc/api/deprecations.md | 5 ++++- lib/zlib.js | 11 +++++++---- test/parallel/test-zlib-bytes-read.js | 6 ++++++ 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/doc/api/deprecations.md b/doc/api/deprecations.md index ca23a4fa322f94..856f6eab2cd6dc 100644 --- a/doc/api/deprecations.md +++ b/doc/api/deprecations.md @@ -2056,12 +2056,15 @@ core and obsoleted by the removal of NPN (Next Protocol Negotiation) support. ### DEP0108: zlib.bytesRead -Type: Documentation-only +Type: Runtime Deprecated alias for [`zlib.bytesWritten`][]. This original name was chosen because it also made sense to interpret the value as the number of bytes diff --git a/lib/zlib.js b/lib/zlib.js index 6fb7696849529d..ab0a86e49c64bf 100644 --- a/lib/zlib.js +++ b/lib/zlib.js @@ -29,6 +29,7 @@ const { } = require('internal/errors').codes; const Transform = require('_stream_transform'); const { + deprecate, _extend, inherits, types: { @@ -333,12 +334,14 @@ Object.defineProperty(Zlib.prototype, '_closed', { Object.defineProperty(Zlib.prototype, 'bytesRead', { configurable: true, enumerable: true, - get() { + get: deprecate(function() { return this.bytesWritten; - }, - set(value) { + }, 'zlib.bytesRead is deprecated and will change its meaning in the ' + + 'future. Use zlib.bytesWritten instead.', 'DEP0108'), + set: deprecate(function(value) { this.bytesWritten = value; - } + }, 'Setting zlib.bytesRead is deprecated. ' + + 'This feature will be removed in the future.', 'DEP0108') }); // This callback is used by `.params()` to wait until a full flush happened diff --git a/test/parallel/test-zlib-bytes-read.js b/test/parallel/test-zlib-bytes-read.js index 493478e78d33d0..e8983efc454f1e 100644 --- a/test/parallel/test-zlib-bytes-read.js +++ b/test/parallel/test-zlib-bytes-read.js @@ -21,6 +21,12 @@ function createWriter(target, buffer) { return writer; } +common.expectWarning( + 'DeprecationWarning', + 'zlib.bytesRead is deprecated and will change its meaning in the ' + + 'future. Use zlib.bytesWritten instead.', + 'DEP0108'); + for (const method of [ ['createGzip', 'createGunzip', false], ['createGzip', 'createUnzip', false], From 4a096aa1b0cdb3b8d0280d0c53dd659037543254 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Sun, 7 Oct 2018 15:43:06 -0700 Subject: [PATCH 2/2] fixup! zlib: move `bytesRead` accessors to runtime deprecation --- doc/api/deprecations.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/api/deprecations.md b/doc/api/deprecations.md index 856f6eab2cd6dc..19f96099f363cf 100644 --- a/doc/api/deprecations.md +++ b/doc/api/deprecations.md @@ -2057,7 +2057,7 @@ core and obsoleted by the removal of NPN (Next Protocol Negotiation) support.