Skip to content

Commit 07682eb

Browse files
addaleaxjasnell
authored andcommitted
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: #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>
1 parent 4f48ddb commit 07682eb

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

doc/api/deprecations.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -2056,12 +2056,15 @@ core and obsoleted by the removal of NPN (Next Protocol Negotiation) support.
20562056
### DEP0108: zlib.bytesRead
20572057
<!-- YAML
20582058
changes:
2059+
- version: REPLACEME
2060+
pr-url: https://github.com/nodejs/node/pull/23308
2061+
description: Runtime deprecation.
20592062
- version: v10.0.0
20602063
pr-url: https://github.com/nodejs/node/pull/19414
20612064
description: Documentation-only deprecation.
20622065
-->
20632066
2064-
Type: Documentation-only
2067+
Type: Runtime
20652068
20662069
Deprecated alias for [`zlib.bytesWritten`][]. This original name was chosen
20672070
because it also made sense to interpret the value as the number of bytes

lib/zlib.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const {
2929
} = require('internal/errors').codes;
3030
const Transform = require('_stream_transform');
3131
const {
32+
deprecate,
3233
_extend,
3334
inherits,
3435
types: {
@@ -334,12 +335,14 @@ Object.defineProperty(Zlib.prototype, '_closed', {
334335
Object.defineProperty(Zlib.prototype, 'bytesRead', {
335336
configurable: true,
336337
enumerable: true,
337-
get() {
338+
get: deprecate(function() {
338339
return this.bytesWritten;
339-
},
340-
set(value) {
340+
}, 'zlib.bytesRead is deprecated and will change its meaning in the ' +
341+
'future. Use zlib.bytesWritten instead.', 'DEP0108'),
342+
set: deprecate(function(value) {
341343
this.bytesWritten = value;
342-
}
344+
}, 'Setting zlib.bytesRead is deprecated. ' +
345+
'This feature will be removed in the future.', 'DEP0108')
343346
});
344347

345348
// This callback is used by `.params()` to wait until a full flush happened

test/parallel/test-zlib-bytes-read.js

+6
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ function createWriter(target, buffer) {
2121
return writer;
2222
}
2323

24+
common.expectWarning(
25+
'DeprecationWarning',
26+
'zlib.bytesRead is deprecated and will change its meaning in the ' +
27+
'future. Use zlib.bytesWritten instead.',
28+
'DEP0108');
29+
2430
for (const method of [
2531
['createGzip', 'createGunzip', false],
2632
['createGzip', 'createUnzip', false],

0 commit comments

Comments
 (0)