2
2
3
3
const {
4
4
ObjectDefineProperties,
5
- Symbol,
6
5
} = primordials ;
7
6
8
7
const {
9
- codes : {
10
- ERR_INVALID_ARG_VALUE ,
11
- ERR_INVALID_THIS ,
12
- } ,
8
+ codes : { ERR_INVALID_ARG_VALUE } ,
13
9
} = require ( 'internal/errors' ) ;
14
10
15
11
const {
@@ -29,119 +25,97 @@ function lazyZlib() {
29
25
return zlib ;
30
26
}
31
27
32
- const kHandle = Symbol ( 'kHandle' ) ;
33
- const kTransform = Symbol ( 'kTransform' ) ;
34
- const kType = Symbol ( 'kType' ) ;
35
-
36
28
/**
37
29
* @typedef {import('./readablestream').ReadableStream } ReadableStream
38
30
* @typedef {import('./writablestream').WritableStream } WritableStream
39
31
*/
40
32
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
-
51
33
class CompressionStream {
34
+ #handle;
35
+ #transform;
36
+
52
37
/**
53
38
* @param {'deflate'|'gzip' } format
54
39
*/
55
40
constructor ( format ) {
56
- this [ kType ] = 'CompressionStream' ;
57
41
switch ( format ) {
58
42
case 'deflate' :
59
- this [ kHandle ] = lazyZlib ( ) . createDeflate ( ) ;
43
+ this . #handle = lazyZlib ( ) . createDeflate ( ) ;
60
44
break ;
61
45
case 'gzip' :
62
- this [ kHandle ] = lazyZlib ( ) . createGzip ( ) ;
46
+ this . #handle = lazyZlib ( ) . createGzip ( ) ;
63
47
break ;
64
48
default :
65
49
throw new ERR_INVALID_ARG_VALUE ( 'format' , format ) ;
66
50
}
67
- this [ kTransform ] = newReadableWritablePairFromDuplex ( this [ kHandle ] ) ;
51
+ this . #transform = newReadableWritablePairFromDuplex ( this . #handle ) ;
68
52
}
69
53
70
54
/**
71
55
* @readonly
72
56
* @type {ReadableStream }
73
57
*/
74
58
get readable ( ) {
75
- if ( ! isCompressionStream ( this ) )
76
- throw new ERR_INVALID_THIS ( 'CompressionStream' ) ;
77
- return this [ kTransform ] . readable ;
59
+ return this . #transform. readable ;
78
60
}
79
61
80
62
/**
81
63
* @readonly
82
64
* @type {WritableStream }
83
65
*/
84
66
get writable ( ) {
85
- if ( ! isCompressionStream ( this ) )
86
- throw new ERR_INVALID_THIS ( 'CompressionStream' ) ;
87
- return this [ kTransform ] . writable ;
67
+ return this . #transform. writable ;
88
68
}
89
69
90
70
[ kInspect ] ( depth , options ) {
91
- if ( ! isCompressionStream ( this ) )
92
- throw new ERR_INVALID_THIS ( 'CompressionStream' ) ;
93
71
customInspect ( depth , options , 'CompressionStream' , {
94
- readable : this [ kTransform ] . readable ,
95
- writable : this [ kTransform ] . writable ,
72
+ readable : this . #transform . readable ,
73
+ writable : this . #transform . writable ,
96
74
} ) ;
97
75
}
98
76
}
99
77
100
78
class DecompressionStream {
79
+ #handle;
80
+ #transform;
81
+
101
82
/**
102
83
* @param {'deflate'|'gzip' } format
103
84
*/
104
85
constructor ( format ) {
105
- this [ kType ] = 'DecompressionStream' ;
106
86
switch ( format ) {
107
87
case 'deflate' :
108
- this [ kHandle ] = lazyZlib ( ) . createInflate ( ) ;
88
+ this . #handle = lazyZlib ( ) . createInflate ( ) ;
109
89
break ;
110
90
case 'gzip' :
111
- this [ kHandle ] = lazyZlib ( ) . createGunzip ( ) ;
91
+ this . #handle = lazyZlib ( ) . createGunzip ( ) ;
112
92
break ;
113
93
default :
114
94
throw new ERR_INVALID_ARG_VALUE ( 'format' , format ) ;
115
95
}
116
- this [ kTransform ] = newReadableWritablePairFromDuplex ( this [ kHandle ] ) ;
96
+ this . #transform = newReadableWritablePairFromDuplex ( this . #handle ) ;
117
97
}
118
98
119
99
/**
120
100
* @readonly
121
101
* @type {ReadableStream }
122
102
*/
123
103
get readable ( ) {
124
- if ( ! isDecompressionStream ( this ) )
125
- throw new ERR_INVALID_THIS ( 'DecompressionStream' ) ;
126
- return this [ kTransform ] . readable ;
104
+ return this . #transform. readable ;
127
105
}
128
106
129
107
/**
130
108
* @readonly
131
109
* @type {WritableStream }
132
110
*/
133
111
get writable ( ) {
134
- if ( ! isDecompressionStream ( this ) )
135
- throw new ERR_INVALID_THIS ( 'DecompressionStream' ) ;
136
- return this [ kTransform ] . writable ;
112
+ return this . #transform. writable ;
137
113
}
138
114
139
115
[ kInspect ] ( depth , options ) {
140
- if ( ! isDecompressionStream ( this ) )
141
- throw new ERR_INVALID_THIS ( 'DecompressionStream' ) ;
142
116
customInspect ( depth , options , 'DecompressionStream' , {
143
- readable : this [ kTransform ] . readable ,
144
- writable : this [ kTransform ] . writable ,
117
+ readable : this . #transform . readable ,
118
+ writable : this . #transform . writable ,
145
119
} ) ;
146
120
}
147
121
}
0 commit comments