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.

PR-URL: https://github.com/nodejs/node/pull/23308
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Anna Henningsen 2018-10-06 18:24:08 -07:00
parent 09c42f45f6
commit b2d8ae0a14
No known key found for this signature in database
GPG Key ID: 9C63F3A6CD2AD8F9
3 changed files with 17 additions and 5 deletions

View File

@ -2056,12 +2056,15 @@ core and obsoleted by the removal of NPN (Next Protocol Negotiation) support.
### DEP0108: zlib.bytesRead ### DEP0108: zlib.bytesRead
<!-- YAML <!-- YAML
changes: changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/23308
description: Runtime deprecation.
- version: v10.0.0 - version: v10.0.0
pr-url: https://github.com/nodejs/node/pull/19414 pr-url: https://github.com/nodejs/node/pull/19414
description: Documentation-only deprecation. description: Documentation-only deprecation.
--> -->
Type: Documentation-only Type: Runtime
Deprecated alias for [`zlib.bytesWritten`][]. This original name was chosen Deprecated alias for [`zlib.bytesWritten`][]. This original name was chosen
because it also made sense to interpret the value as the number of bytes because it also made sense to interpret the value as the number of bytes

View File

@ -29,6 +29,7 @@ const {
} = require('internal/errors').codes; } = require('internal/errors').codes;
const Transform = require('_stream_transform'); const Transform = require('_stream_transform');
const { const {
deprecate,
_extend, _extend,
inherits, inherits,
types: { types: {
@ -334,12 +335,14 @@ Object.defineProperty(Zlib.prototype, '_closed', {
Object.defineProperty(Zlib.prototype, 'bytesRead', { Object.defineProperty(Zlib.prototype, 'bytesRead', {
configurable: true, configurable: true,
enumerable: true, enumerable: true,
get() { get: deprecate(function() {
return this.bytesWritten; return this.bytesWritten;
}, }, 'zlib.bytesRead is deprecated and will change its meaning in the ' +
set(value) { 'future. Use zlib.bytesWritten instead.', 'DEP0108'),
set: deprecate(function(value) {
this.bytesWritten = 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 // This callback is used by `.params()` to wait until a full flush happened

View File

@ -21,6 +21,12 @@ function createWriter(target, buffer) {
return writer; 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 [ for (const method of [
['createGzip', 'createGunzip', false], ['createGzip', 'createGunzip', false],
['createGzip', 'createUnzip', false], ['createGzip', 'createUnzip', false],