mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
zlib: avoid converting Uint8Array
instances to Buffer
PR-URL: https://github.com/nodejs/node/pull/39492 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Zeyu Yang <himself65@outlook.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
parent
da0ede1ad5
commit
c1354ffec3
@ -34,7 +34,6 @@ const {
|
||||
ObjectDefineProperties,
|
||||
ObjectDefineProperty,
|
||||
ObjectFreeze,
|
||||
ObjectGetPrototypeOf,
|
||||
ObjectKeys,
|
||||
ObjectSetPrototypeOf,
|
||||
ReflectApply,
|
||||
@ -60,7 +59,8 @@ const {
|
||||
} = require('internal/util');
|
||||
const {
|
||||
isArrayBufferView,
|
||||
isAnyArrayBuffer
|
||||
isAnyArrayBuffer,
|
||||
isUint8Array,
|
||||
} = require('internal/util/types');
|
||||
const binding = internalBinding('zlib');
|
||||
const assert = require('internal/assert');
|
||||
@ -112,10 +112,9 @@ for (const ckey of ObjectKeys(codes)) {
|
||||
|
||||
function zlibBuffer(engine, buffer, callback) {
|
||||
validateFunction(callback, 'callback');
|
||||
// Streams do not support non-Buffer ArrayBufferViews yet. Convert it to a
|
||||
// Streams do not support non-Uint8Array ArrayBufferViews yet. Convert it to a
|
||||
// Buffer without copying.
|
||||
if (isArrayBufferView(buffer) &&
|
||||
ObjectGetPrototypeOf(buffer) !== Buffer.prototype) {
|
||||
if (isArrayBufferView(buffer) && !isUint8Array(buffer)) {
|
||||
buffer = Buffer.from(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
||||
} else if (isAnyArrayBuffer(buffer)) {
|
||||
buffer = Buffer.from(buffer);
|
||||
|
Loading…
Reference in New Issue
Block a user