Skip to content

Commit 0405c8d

Browse files
aduh95targos
authored andcommitted
zlib: avoid converting Uint8Array instances to Buffer
PR-URL: #39492 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Zeyu Yang <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent e13162d commit 0405c8d

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

Diff for: lib/zlib.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ const {
3434
ObjectDefineProperties,
3535
ObjectDefineProperty,
3636
ObjectFreeze,
37-
ObjectGetPrototypeOf,
3837
ObjectKeys,
3938
ObjectSetPrototypeOf,
4039
ReflectApply,
@@ -60,7 +59,8 @@ const {
6059
} = require('internal/util');
6160
const {
6261
isArrayBufferView,
63-
isAnyArrayBuffer
62+
isAnyArrayBuffer,
63+
isUint8Array,
6464
} = require('internal/util/types');
6565
const binding = internalBinding('zlib');
6666
const assert = require('internal/assert');
@@ -112,10 +112,9 @@ for (const ckey of ObjectKeys(codes)) {
112112

113113
function zlibBuffer(engine, buffer, callback) {
114114
validateFunction(callback, 'callback');
115-
// Streams do not support non-Buffer ArrayBufferViews yet. Convert it to a
115+
// Streams do not support non-Uint8Array ArrayBufferViews yet. Convert it to a
116116
// Buffer without copying.
117-
if (isArrayBufferView(buffer) &&
118-
ObjectGetPrototypeOf(buffer) !== Buffer.prototype) {
117+
if (isArrayBufferView(buffer) && !isUint8Array(buffer)) {
119118
buffer = Buffer.from(buffer.buffer, buffer.byteOffset, buffer.byteLength);
120119
} else if (isAnyArrayBuffer(buffer)) {
121120
buffer = Buffer.from(buffer);

0 commit comments

Comments
 (0)