File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -109,6 +109,31 @@ http.createServer((request, response) => {
109
109
}).listen (1337 );
110
110
```
111
111
112
+ By default, the zlib methods with throw an error when decompressing
113
+ truncated data. However, if it is known that the data is incomplete, or
114
+ the desire is to inspect only the beginning of a compressed file, it is
115
+ possible to suppress the default error handling by changing the flushing
116
+ method that is used to compressed the last chunk of input data:
117
+
118
+ ``` js
119
+ // This is a truncated version of the buffer from the above examples
120
+ const buffer = new Buffer (' eJzT0yMA' , ' base64' );
121
+
122
+ zlib .unzip (buffer, { finishFlush: zlib .Z_SYNC_FLUSH }, (err , buffer ) => {
123
+ if (! err) {
124
+ console .log (buffer .toString ());
125
+ } else {
126
+ // handle error
127
+ }
128
+ });
129
+ ```
130
+
131
+ This will not change the behavior in other error-throwing situations, e.g.
132
+ when the input data has an invalid format. Using this method, it will not be
133
+ possible to determine whether the input ended prematurely or lacks the
134
+ integrity checks, making it necessary to manually check that the
135
+ decompressed result is valid.
136
+
112
137
## Memory Usage Tuning
113
138
114
139
<!-- type=misc-->
You can’t perform that action at this time.
0 commit comments