diff options
author | Anna Henningsen <anna@addaleax.net> | 2018-03-17 16:59:54 +0100 |
---|---|---|
committer | Ruben Bridgewater <ruben@bridgewater.de> | 2018-04-10 00:36:26 +0200 |
commit | 49fd9c63d21c8c42a110996a6a68bf1fdcee12b4 (patch) | |
tree | 1ce3f7768a33e36ed6807f27d470407563f8275c /lib | |
parent | cc6abc6e84b96fd5f1c4123066eba93ddb637e60 (diff) | |
download | android-node-v8-49fd9c63d21c8c42a110996a6a68bf1fdcee12b4.tar.gz android-node-v8-49fd9c63d21c8c42a110996a6a68bf1fdcee12b4.tar.bz2 android-node-v8-49fd9c63d21c8c42a110996a6a68bf1fdcee12b4.zip |
zlib: use `.bytesWritten` instead of `.bytesRead`
The introduction of `.bytesRead` to zlib streams was unfortunate,
because other streams in Node.js core use the exact opposite naming
of `.bytesRead` and `.bytesWritten`.
While one could see how the original naming makes sense in
a `Transform` stream context, we should try to work towards more
consistent APIs in core for these things.
This introduces `zlib.bytesWritten` and documentation-only deprecates
`zlib.bytesRead`.
PR-URL: https://github.com/nodejs/node/pull/19414
Refs: https://github.com/nodejs/node/issues/8874
Refs: https://github.com/nodejs/node/pull/13088
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/zlib.js | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/lib/zlib.js b/lib/zlib.js index 01a2ebe933..a39e9c20ee 100644 --- a/lib/zlib.js +++ b/lib/zlib.js @@ -288,7 +288,7 @@ function Zlib(opts, mode) { } } Transform.call(this, opts); - this.bytesRead = 0; + this.bytesWritten = 0; this._handle = new binding.Zlib(mode); this._handle.jsref = this; // Used by processCallback() and zlibOnError() this._handle.onerror = zlibOnError; @@ -327,6 +327,21 @@ Object.defineProperty(Zlib.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). +Object.defineProperty(Zlib.prototype, 'bytesRead', { + configurable: true, + enumerable: true, + get() { + return this.bytesWritten; + }, + set(value) { + this.bytesWritten = value; + } +}); + Zlib.prototype.params = function params(level, strategy, callback) { checkRangesOrGetDefault(level, 'level', Z_MIN_LEVEL, Z_MAX_LEVEL); checkRangesOrGetDefault(strategy, 'strategy', Z_DEFAULT_STRATEGY, Z_FIXED); @@ -501,7 +516,7 @@ function processChunkSync(self, chunk, flushFlag) { } } - self.bytesRead = inputRead; + self.bytesWritten = inputRead; if (nread >= kMaxLength) { _close(self); @@ -558,8 +573,8 @@ function processCallback() { var availOutAfter = state[0]; var availInAfter = state[1]; - var inDelta = (handle.availInBefore - availInAfter); - self.bytesRead += inDelta; + const inDelta = handle.availInBefore - availInAfter; + self.bytesWritten += inDelta; var have = handle.availOutBefore - availOutAfter; if (have > 0) { |