22
33const {
44 ObjectDefineProperties,
5- Symbol,
65} = primordials ;
76
87const {
9- codes : {
10- ERR_INVALID_ARG_VALUE ,
11- ERR_INVALID_THIS ,
12- } ,
8+ codes : { ERR_INVALID_ARG_VALUE } ,
139} = require ( 'internal/errors' ) ;
1410
1511const {
@@ -29,119 +25,97 @@ function lazyZlib() {
2925 return zlib ;
3026}
3127
32- const kHandle = Symbol ( 'kHandle' ) ;
33- const kTransform = Symbol ( 'kTransform' ) ;
34- const kType = Symbol ( 'kType' ) ;
35-
3628/**
3729 * @typedef {import('./readablestream').ReadableStream } ReadableStream
3830 * @typedef {import('./writablestream').WritableStream } WritableStream
3931 */
4032
41- function isCompressionStream ( value ) {
42- return typeof value ?. [ kHandle ] === 'object' &&
43- value ?. [ kType ] === 'CompressionStream' ;
44- }
45-
46- function isDecompressionStream ( value ) {
47- return typeof value ?. [ kHandle ] === 'object' &&
48- value ?. [ kType ] === 'DecompressionStream' ;
49- }
50-
5133class CompressionStream {
34+ #handle;
35+ #transform;
36+
5237 /**
5338 * @param {'deflate'|'gzip' } format
5439 */
5540 constructor ( format ) {
56- this [ kType ] = 'CompressionStream' ;
5741 switch ( format ) {
5842 case 'deflate' :
59- this [ kHandle ] = lazyZlib ( ) . createDeflate ( ) ;
43+ this . #handle = lazyZlib ( ) . createDeflate ( ) ;
6044 break ;
6145 case 'gzip' :
62- this [ kHandle ] = lazyZlib ( ) . createGzip ( ) ;
46+ this . #handle = lazyZlib ( ) . createGzip ( ) ;
6347 break ;
6448 default :
6549 throw new ERR_INVALID_ARG_VALUE ( 'format' , format ) ;
6650 }
67- this [ kTransform ] = newReadableWritablePairFromDuplex ( this [ kHandle ] ) ;
51+ this . #transform = newReadableWritablePairFromDuplex ( this . #handle ) ;
6852 }
6953
7054 /**
7155 * @readonly
7256 * @type {ReadableStream }
7357 */
7458 get readable ( ) {
75- if ( ! isCompressionStream ( this ) )
76- throw new ERR_INVALID_THIS ( 'CompressionStream' ) ;
77- return this [ kTransform ] . readable ;
59+ return this . #transform. readable ;
7860 }
7961
8062 /**
8163 * @readonly
8264 * @type {WritableStream }
8365 */
8466 get writable ( ) {
85- if ( ! isCompressionStream ( this ) )
86- throw new ERR_INVALID_THIS ( 'CompressionStream' ) ;
87- return this [ kTransform ] . writable ;
67+ return this . #transform. writable ;
8868 }
8969
9070 [ kInspect ] ( depth , options ) {
91- if ( ! isCompressionStream ( this ) )
92- throw new ERR_INVALID_THIS ( 'CompressionStream' ) ;
9371 customInspect ( depth , options , 'CompressionStream' , {
94- readable : this [ kTransform ] . readable ,
95- writable : this [ kTransform ] . writable ,
72+ readable : this . #transform . readable ,
73+ writable : this . #transform . writable ,
9674 } ) ;
9775 }
9876}
9977
10078class DecompressionStream {
79+ #handle;
80+ #transform;
81+
10182 /**
10283 * @param {'deflate'|'gzip' } format
10384 */
10485 constructor ( format ) {
105- this [ kType ] = 'DecompressionStream' ;
10686 switch ( format ) {
10787 case 'deflate' :
108- this [ kHandle ] = lazyZlib ( ) . createInflate ( ) ;
88+ this . #handle = lazyZlib ( ) . createInflate ( ) ;
10989 break ;
11090 case 'gzip' :
111- this [ kHandle ] = lazyZlib ( ) . createGunzip ( ) ;
91+ this . #handle = lazyZlib ( ) . createGunzip ( ) ;
11292 break ;
11393 default :
11494 throw new ERR_INVALID_ARG_VALUE ( 'format' , format ) ;
11595 }
116- this [ kTransform ] = newReadableWritablePairFromDuplex ( this [ kHandle ] ) ;
96+ this . #transform = newReadableWritablePairFromDuplex ( this . #handle ) ;
11797 }
11898
11999 /**
120100 * @readonly
121101 * @type {ReadableStream }
122102 */
123103 get readable ( ) {
124- if ( ! isDecompressionStream ( this ) )
125- throw new ERR_INVALID_THIS ( 'DecompressionStream' ) ;
126- return this [ kTransform ] . readable ;
104+ return this . #transform. readable ;
127105 }
128106
129107 /**
130108 * @readonly
131109 * @type {WritableStream }
132110 */
133111 get writable ( ) {
134- if ( ! isDecompressionStream ( this ) )
135- throw new ERR_INVALID_THIS ( 'DecompressionStream' ) ;
136- return this [ kTransform ] . writable ;
112+ return this . #transform. writable ;
137113 }
138114
139115 [ kInspect ] ( depth , options ) {
140- if ( ! isDecompressionStream ( this ) )
141- throw new ERR_INVALID_THIS ( 'DecompressionStream' ) ;
142116 customInspect ( depth , options , 'DecompressionStream' , {
143- readable : this [ kTransform ] . readable ,
144- writable : this [ kTransform ] . writable ,
117+ readable : this . #transform . readable ,
118+ writable : this . #transform . writable ,
145119 } ) ;
146120 }
147121}
0 commit comments