mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 13:09:21 +01:00
zlib: remove zlib.bytesRead
Use `zlib.bytesWritten` instead. PR-URL: https://github.com/nodejs/node/pull/55020 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
This commit is contained in:
parent
f805d0be95
commit
e225f00034
@ -2290,6 +2290,9 @@ core and obsoleted by the removal of NPN (Next Protocol Negotiation) support.
|
||||
|
||||
<!-- YAML
|
||||
changes:
|
||||
- version: REPLACEME
|
||||
pr-url: https://github.com/nodejs/node/pull/55020
|
||||
description: End-of-Life.
|
||||
- version: v11.0.0
|
||||
pr-url: https://github.com/nodejs/node/pull/23308
|
||||
description: Runtime deprecation.
|
||||
@ -2298,7 +2301,7 @@ changes:
|
||||
description: Documentation-only deprecation.
|
||||
-->
|
||||
|
||||
Type: Runtime
|
||||
Type: End-of-Life
|
||||
|
||||
Deprecated alias for [`zlib.bytesWritten`][]. This original name was chosen
|
||||
because it also made sense to interpret the value as the number of bytes
|
||||
|
@ -684,22 +684,6 @@ base class of the compressor/decompressor classes.
|
||||
This class inherits from [`stream.Transform`][], allowing `node:zlib` objects to
|
||||
be used in pipes and similar stream operations.
|
||||
|
||||
### `zlib.bytesRead`
|
||||
|
||||
<!-- YAML
|
||||
added: v8.1.0
|
||||
deprecated: v10.0.0
|
||||
-->
|
||||
|
||||
> Stability: 0 - Deprecated: Use [`zlib.bytesWritten`][] instead.
|
||||
|
||||
* {number}
|
||||
|
||||
Deprecated alias for [`zlib.bytesWritten`][]. This original name was chosen
|
||||
because it also made sense to interpret the value as the number of bytes
|
||||
read by the engine, but is inconsistent with other streams in Node.js that
|
||||
expose values under these names.
|
||||
|
||||
### `zlib.bytesWritten`
|
||||
|
||||
<!-- YAML
|
||||
@ -1307,7 +1291,6 @@ Decompress a chunk of data with [`Unzip`][].
|
||||
[`buffer.kMaxLength`]: buffer.md#bufferkmaxlength
|
||||
[`deflateInit2` and `inflateInit2`]: https://zlib.net/manual.html#Advanced
|
||||
[`stream.Transform`]: stream.md#class-streamtransform
|
||||
[`zlib.bytesWritten`]: #zlibbyteswritten
|
||||
[convenience methods]: #convenience-methods
|
||||
[zlib documentation]: https://zlib.net/manual.html#Constants
|
||||
[zlib.createGzip example]: #zlib
|
||||
|
21
lib/zlib.js
21
lib/zlib.js
@ -46,9 +46,6 @@ const {
|
||||
genericNodeError,
|
||||
} = require('internal/errors');
|
||||
const { Transform, finished } = require('stream');
|
||||
const {
|
||||
deprecate,
|
||||
} = require('internal/util');
|
||||
const {
|
||||
isArrayBufferView,
|
||||
isAnyArrayBuffer,
|
||||
@ -271,24 +268,6 @@ ObjectDefineProperty(ZlibBase.prototype, '_closed', {
|
||||
},
|
||||
});
|
||||
|
||||
// `bytesRead` made sense as a name when looking from the zlib engine's
|
||||
// perspective, but it is inconsistent with all other streams exposed by Node.js
|
||||
// that have this concept, where it stands for the number of bytes read
|
||||
// *from* the stream (that is, net.Socket/tls.Socket & file system streams).
|
||||
ObjectDefineProperty(ZlibBase.prototype, 'bytesRead', {
|
||||
__proto__: null,
|
||||
configurable: true,
|
||||
enumerable: true,
|
||||
get: deprecate(function() {
|
||||
return this.bytesWritten;
|
||||
}, '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 ZlibBase
|
||||
* @returns {void}
|
||||
|
@ -1,102 +0,0 @@
|
||||
'use strict';
|
||||
const common = require('../common');
|
||||
const assert = require('assert');
|
||||
const zlib = require('zlib');
|
||||
|
||||
const expectStr = 'abcdefghijklmnopqrstuvwxyz'.repeat(2);
|
||||
const expectBuf = Buffer.from(expectStr);
|
||||
|
||||
function createWriter(target, buffer) {
|
||||
const writer = { size: 0 };
|
||||
const write = () => {
|
||||
target.write(Buffer.from([buffer[writer.size++]]), () => {
|
||||
if (writer.size < buffer.length) {
|
||||
target.flush(write);
|
||||
} else {
|
||||
target.end();
|
||||
}
|
||||
});
|
||||
};
|
||||
write();
|
||||
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],
|
||||
['createDeflate', 'createInflate', true],
|
||||
['createDeflateRaw', 'createInflateRaw', true],
|
||||
['createBrotliCompress', 'createBrotliDecompress', true],
|
||||
]) {
|
||||
let compWriter;
|
||||
let compData = Buffer.alloc(0);
|
||||
|
||||
const comp = zlib[method[0]]();
|
||||
comp.on('data', function(d) {
|
||||
compData = Buffer.concat([compData, d]);
|
||||
assert.strictEqual(this.bytesWritten, compWriter.size,
|
||||
`Should get write size on ${method[0]} data.`);
|
||||
});
|
||||
comp.on('end', common.mustCall(function() {
|
||||
assert.strictEqual(this.bytesWritten, compWriter.size,
|
||||
`Should get write size on ${method[0]} end.`);
|
||||
assert.strictEqual(this.bytesWritten, expectStr.length,
|
||||
`Should get data size on ${method[0]} end.`);
|
||||
|
||||
{
|
||||
let decompWriter;
|
||||
let decompData = Buffer.alloc(0);
|
||||
|
||||
const decomp = zlib[method[1]]();
|
||||
decomp.on('data', function(d) {
|
||||
decompData = Buffer.concat([decompData, d]);
|
||||
assert.strictEqual(this.bytesWritten, decompWriter.size,
|
||||
`Should get write size on ${method[0]}/` +
|
||||
`${method[1]} data.`);
|
||||
});
|
||||
decomp.on('end', common.mustCall(function() {
|
||||
assert.strictEqual(this.bytesWritten, compData.length,
|
||||
`Should get compressed size on ${method[0]}/` +
|
||||
`${method[1]} end.`);
|
||||
assert.strictEqual(decompData.toString(), expectStr,
|
||||
`Should get original string on ${method[0]}/` +
|
||||
`${method[1]} end.`);
|
||||
}));
|
||||
decompWriter = createWriter(decomp, compData);
|
||||
}
|
||||
|
||||
// Some methods should allow extra data after the compressed data
|
||||
if (method[2]) {
|
||||
const compDataExtra = Buffer.concat([compData, Buffer.from('extra')]);
|
||||
|
||||
let decompWriter;
|
||||
let decompData = Buffer.alloc(0);
|
||||
|
||||
const decomp = zlib[method[1]]();
|
||||
decomp.on('data', function(d) {
|
||||
decompData = Buffer.concat([decompData, d]);
|
||||
assert.strictEqual(this.bytesWritten, decompWriter.size,
|
||||
`Should get write size on ${method[0]}/` +
|
||||
`${method[1]} data.`);
|
||||
});
|
||||
decomp.on('end', common.mustCall(function() {
|
||||
assert.strictEqual(this.bytesWritten, compData.length,
|
||||
`Should get compressed size on ${method[0]}/` +
|
||||
`${method[1]} end.`);
|
||||
// Checking legacy name.
|
||||
assert.strictEqual(this.bytesWritten, this.bytesRead);
|
||||
assert.strictEqual(decompData.toString(), expectStr,
|
||||
`Should get original string on ${method[0]}/` +
|
||||
`${method[1]} end.`);
|
||||
}));
|
||||
decompWriter = createWriter(decomp, compDataExtra);
|
||||
}
|
||||
}));
|
||||
compWriter = createWriter(comp, expectBuf);
|
||||
}
|
Loading…
Reference in New Issue
Block a user