Skip to content

Commit

Permalink
fixup! streams: add CompressionStream and DecompressionStream
Browse files Browse the repository at this point in the history
  • Loading branch information
jasnell committed Jul 14, 2021
1 parent 1e09cb6 commit 3797a84
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions lib/internal/webstreams/compression.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,11 @@ const {
customInspectSymbol: kInspect,
} = require('internal/util');

const {
createDeflate,
createInflate,
createGzip,
createGunzip,
} = require('zlib');
let zlib;
function lazyZlib() {
zlib ??= require('zlib');
return zlib;
}

const kHandle = Symbol('kHandle');
const kTransform = Symbol('kTransform');
Expand Down Expand Up @@ -59,10 +58,10 @@ class CompressionStream {
this[kType] = 'CompressionStream';
switch (format) {
case 'deflate':
this[kHandle] = createDeflate();
this[kHandle] = lazyZlib().createDeflate();
break;
case 'gzip':
this[kHandle] = createGzip();
this[kHandle] = lazyZlib().createGzip();
break;
default:
throw new ERR_INVALID_ARG_VALUE('format', format);
Expand Down Expand Up @@ -108,10 +107,10 @@ class DecompressionStream {
this[kType] = 'DecompressionStream';
switch (format) {
case 'deflate':
this[kHandle] = createInflate();
this[kHandle] = lazyZlib().createInflate();
break;
case 'gzip':
this[kHandle] = createGunzip();
this[kHandle] = lazyZlib().createGunzip();
break;
default:
throw new ERR_INVALID_ARG_VALUE('format', format);
Expand Down

0 comments on commit 3797a84

Please sign in to comment.