@@ -24,7 +24,7 @@ exports.UNZIP = 7;
24
24
function Zlib ( mode ) {
25
25
if ( mode < exports . DEFLATE || mode > exports . UNZIP )
26
26
throw new TypeError ( "Bad argument" ) ;
27
-
27
+
28
28
this . mode = mode ;
29
29
this . init_done = false ;
30
30
this . write_in_progress = false ;
@@ -42,18 +42,18 @@ Zlib.prototype.init = function(windowBits, level, memLevel, strategy, dictionary
42
42
this . memLevel = memLevel ;
43
43
this . strategy = strategy ;
44
44
// dictionary not supported.
45
-
45
+
46
46
if ( this . mode === exports . GZIP || this . mode === exports . GUNZIP )
47
47
this . windowBits += 16 ;
48
-
48
+
49
49
if ( this . mode === exports . UNZIP )
50
50
this . windowBits += 32 ;
51
-
51
+
52
52
if ( this . mode === exports . DEFLATERAW || this . mode === exports . INFLATERAW )
53
53
this . windowBits = - this . windowBits ;
54
-
54
+
55
55
this . strm = new zstream ( ) ;
56
-
56
+
57
57
switch ( this . mode ) {
58
58
case exports . DEFLATE :
59
59
case exports . GZIP :
@@ -79,12 +79,12 @@ Zlib.prototype.init = function(windowBits, level, memLevel, strategy, dictionary
79
79
default :
80
80
throw new Error ( "Unknown mode " + this . mode ) ;
81
81
}
82
-
82
+
83
83
if ( status !== exports . Z_OK ) {
84
84
this . _error ( status ) ;
85
85
return ;
86
86
}
87
-
87
+
88
88
this . write_in_progress = false ;
89
89
this . init_done = true ;
90
90
} ;
@@ -96,31 +96,31 @@ Zlib.prototype.params = function() {
96
96
Zlib . prototype . _writeCheck = function ( ) {
97
97
if ( ! this . init_done )
98
98
throw new Error ( "write before init" ) ;
99
-
99
+
100
100
if ( this . mode === exports . NONE )
101
101
throw new Error ( "already finalized" ) ;
102
-
102
+
103
103
if ( this . write_in_progress )
104
104
throw new Error ( "write already in progress" ) ;
105
-
105
+
106
106
if ( this . pending_close )
107
107
throw new Error ( "close is pending" ) ;
108
108
} ;
109
109
110
- Zlib . prototype . write = function ( flush , input , in_off , in_len , out , out_off , out_len ) {
110
+ Zlib . prototype . write = function ( flush , input , in_off , in_len , out , out_off , out_len ) {
111
111
this . _writeCheck ( ) ;
112
112
this . write_in_progress = true ;
113
-
113
+
114
114
var self = this ;
115
115
process . nextTick ( function ( ) {
116
116
self . write_in_progress = false ;
117
117
var res = self . _write ( flush , input , in_off , in_len , out , out_off , out_len ) ;
118
118
self . callback ( res [ 0 ] , res [ 1 ] ) ;
119
-
119
+
120
120
if ( self . pending_close )
121
121
self . close ( ) ;
122
122
} ) ;
123
-
123
+
124
124
return this ;
125
125
} ;
126
126
@@ -138,7 +138,7 @@ Zlib.prototype.writeSync = function(flush, input, in_off, in_len, out, out_off,
138
138
139
139
Zlib . prototype . _write = function ( flush , input , in_off , in_len , out , out_off , out_len ) {
140
140
this . write_in_progress = true ;
141
-
141
+
142
142
if ( flush !== exports . Z_NO_FLUSH &&
143
143
flush !== exports . Z_PARTIAL_FLUSH &&
144
144
flush !== exports . Z_SYNC_FLUSH &&
@@ -147,26 +147,26 @@ Zlib.prototype._write = function(flush, input, in_off, in_len, out, out_off, out
147
147
flush !== exports . Z_BLOCK ) {
148
148
throw new Error ( "Invalid flush value" ) ;
149
149
}
150
-
150
+
151
151
if ( input == null ) {
152
152
input = new Buffer ( 0 ) ;
153
153
in_len = 0 ;
154
154
in_off = 0 ;
155
155
}
156
-
156
+
157
157
if ( out . _set )
158
158
out . set = out . _set ;
159
159
else
160
160
out . set = bufferSet ;
161
-
161
+
162
162
var strm = this . strm ;
163
163
strm . avail_in = in_len ;
164
164
strm . input = input ;
165
165
strm . next_in = in_off ;
166
166
strm . avail_out = out_len ;
167
167
strm . output = out ;
168
168
strm . next_out = out_off ;
169
-
169
+
170
170
switch ( this . mode ) {
171
171
case exports . DEFLATE :
172
172
case exports . GZIP :
@@ -182,11 +182,11 @@ Zlib.prototype._write = function(flush, input, in_off, in_len, out, out_off, out
182
182
default :
183
183
throw new Error ( "Unknown mode " + this . mode ) ;
184
184
}
185
-
185
+
186
186
if ( status !== exports . Z_STREAM_END && status !== exports . Z_OK ) {
187
187
this . _error ( status ) ;
188
188
}
189
-
189
+
190
190
this . write_in_progress = false ;
191
191
return [ strm . avail_in , strm . avail_out ] ;
192
192
} ;
@@ -196,15 +196,15 @@ Zlib.prototype.close = function() {
196
196
this . pending_close = true ;
197
197
return ;
198
198
}
199
-
199
+
200
200
this . pending_close = false ;
201
-
201
+
202
202
if ( this . mode === exports . DEFLATE || this . mode === exports . GZIP || this . mode === exports . DEFLATERAW ) {
203
203
zlib_deflate . deflateEnd ( this . strm ) ;
204
204
} else {
205
205
zlib_inflate . inflateEnd ( this . strm ) ;
206
206
}
207
-
207
+
208
208
this . mode = exports . NONE ;
209
209
} ;
210
210
@@ -219,15 +219,15 @@ Zlib.prototype.reset = function() {
219
219
var status = zlib_inflate . inflateReset ( this . strm ) ;
220
220
break ;
221
221
}
222
-
222
+
223
223
if ( status !== exports . Z_OK ) {
224
224
this . _error ( status ) ;
225
225
}
226
226
} ;
227
227
228
228
Zlib . prototype . _error = function ( status ) {
229
229
this . onerror ( msg [ status ] + ': ' + this . strm . msg , status ) ;
230
-
230
+
231
231
this . write_in_progress = false ;
232
232
if ( this . pending_close )
233
233
this . close ( ) ;
0 commit comments