• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Compressing and Decompressing Files
2<!--Kit: Ability Kit-->
3<!--Subsystem: BundleManager-->
4<!--Owner: @jinsenjun-->
5<!--Designer: @jinsenjun-->
6<!--Tester: @lixueqing-->
7<!--Adviser: @Brilliantry_Rui-->
8
9This topic describes how to use functions in common compression and decompression scenarios.
10
11## Available APIs
12
13For details about more APIs and their usage, see [Zip](../../reference/apis-basic-services-kit/js-apis-zlib.md).
14
15| API                                                      | Description                    |
16| ------------------------------------------------------------ | ---------------------------- |
17| compressFile(inFile: string, outFile: string, options: Options): Promise&lt;void&gt; | Compresses a file.              |
18| decompressFile(inFile: string, outFile: string, options?: Options): Promise&lt;void&gt; | Decompresses a file.              |
19| compress(dest: ArrayBuffer, source: ArrayBuffer, sourceLen?: number): Promise&lt;ZipOutputInfo&gt; | Compresses the source buffer into the destination buffer.              |
20| compressBound(sourceLen: number): Promise&lt;number&gt; | Calculates the upper limit of the compression size to return.             |
21| uncompress(dest:ArrayBuffer, source: ArrayBuffer, sourceLen?: number): Promise&lt;ZipOutputInfo&gt; | Decompresses the compressed data into an original uncompressed one.              |
22| deflate(strm: ZStream, flush: CompressFlushMode): Promise&lt;ReturnStatus&gt; | Deflates data.              |
23| inflate(strm: ZStream, flush: CompressFlushMode): Promise&lt;ReturnStatus&gt; | Inflates data.|
24
25## How to Develop
26
27### Environment Preparations
28
29Create a test file **data.txt** in the application sandbox directory and write data for testing. The sample code is as follows:
30
31   ```ts
32   import { fileIo as fs} from '@kit.CoreFileKit';
33   import { BusinessError, zlib } from '@kit.BasicServicesKit';
34
35   @Entry
36   @Component
37   struct Index {
38     @State dataSize: number = 0;
39
40     build() {
41       Row() {
42         Column() {
43           // Create the data.txt file and write test data.
44           Button('Create a test file data.txt').onClick(() => {
45             let path = this.getUIContext()?.getHostContext()?.filesDir;
46             // Create the data.txt file.
47             let inFile = fs.openSync(path + '/data.txt', fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE);
48             // Write test data.
49             for (let index = 0; index < 100; index++) {
50               fs.writeSync(inFile.fd, index + ': hello world, hello world, hello world, hello world, hello world.\n');
51             }
52             // Obtain the original size of the test data and save it to dataSize.
53             let stat = fs.statSync(inFile.path);
54             this.dataSize = stat.size;
55             console.info('dataSize: ' + this.dataSize);
56             // Close the file.
57             fs.closeSync(inFile);
58           })
59         }
60       }
61       .height('100%')
62       .width('100%')
63     }
64   }
65   ```
66
67### Compressing and Decompressing .zip Files
68
69Use [zlib.compressFile()](../../reference/apis-basic-services-kit/js-apis-zlib.md#zlibcompressfile9-1) to compress the **data.txt** into to the **data.zip** file, and use [zlib.decompressFile()](../../reference/apis-basic-services-kit/js-apis-zlib.md#zlibdecompressfile9-1) to decompress the .zip file to the application sandbox directory. The sample code is as follows:
70
71   ```ts
72   import { fileIo as fs} from '@kit.CoreFileKit';
73   import { BusinessError, zlib } from '@kit.BasicServicesKit';
74
75   @Entry
76   @Component
77   struct Index {
78     build() {
79       Row() {
80         // Example 1: Compress the data.txt file into the data.zip file.
81         Button('compressFile').onClick(() => {
82           let path = this.getUIContext()?.getHostContext()?.filesDir;
83           let inFile = path + '/data.txt';
84           let outFile = path + '/data.zip';
85           let options: zlib.Options = {};
86           zlib.compressFile(inFile, outFile, options).then((data: void) => {
87             console.info('compressFile success, data: ' + JSON.stringify(data));
88           }).catch((errData: BusinessError) => {
89             console.error(`compressFile errCode: ${errData.code}, message: ${errData.message}`);
90           })
91         })
92
93         // Example 2: Decompress the data.zip file to the application sandbox directory.
94         Button('decompressFile').onClick(() => {
95           let path = this.getUIContext()?.getHostContext()?.filesDir;
96           let inFile = path + '/data.zip';
97           let outFile = path;
98           let options: zlib.Options = {};
99           zlib.decompressFile(inFile, outFile, options).then((data: void) => {
100             console.info('decompressFile success, data: ' + JSON.stringify(data));
101           }).catch((errData: BusinessError) => {
102             console.error(`decompressFile errCode: ${errData.code}, message: ${errData.message}`);
103           })
104         })
105       }
106       .height('100%')
107       .width('100%')
108     }
109   }
110   ```
111
112### Compressing and Decompressing Buffers of Known Sizes
113
114For data in a buffer with a known size, use [compress()](../../reference/apis-basic-services-kit/js-apis-zlib.md#compress12) to compress the data into a destination buffer, [compressBound()](../../reference/apis-basic-services-kit/js-apis-zlib.md#compressbound12) to calculate the upper limit of the compression size of the destination buffer, and [uncompress()](../../reference/apis-basic-services-kit/js-apis-zlib.md#uncompress12) to decompress the buffer that stores the compressed data. To check the size of the destination buffer after decompression, obtain and save the original data size before compression. The sample code is as follows:
115
116   ```ts
117   import { fileIo as fs} from '@kit.CoreFileKit';
118   import { BusinessError, zlib } from '@kit.BasicServicesKit';
119
120   @Entry
121   @Component
122   struct Index {
123     @State dataSize: number = 0; // Size of the original data.
124
125     build() {
126       Row() {
127         // Example 1: Read the data.txt file and save it to a buffer. Call the compress API to compress the data in the source buffer to the destination buffer and write the content in the destination buffer to the data.bin file.
128         Button('compress buffer').onClick(() => {
129           let path = this.getUIContext()?.getHostContext()?.filesDir;
130           let inFile = fs.openSync(path + '/data.txt', fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE);
131           let outFile = fs.openSync(path + '/data.bin', fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE);
132           // Read the content of the data.txt file and save the content to the buffer inBuf.
133           let stat = fs.statSync(inFile.path);
134           let inBuf = new ArrayBuffer(stat.size);
135           let readLen = fs.readSync(inFile.fd, inBuf);
136           console.info(`original size: ${stat.size}, read len: ${readLen}`);
137           // Obtain the size of the original data and save it.
138           this.dataSize = stat.size;
139           // Create a compressed object instance.
140           let zip = zlib.createZipSync();
141           // Obtain the upper limit of a destination buffer.
142           zip.compressBound(stat.size).then((data) => {
143             console.info(`the max dest buf len is ${data}`);
144             // Destination buffer outBuf.
145             let outBuf = new ArrayBuffer(data);
146             // Compress the data in inBuf to outBuf.
147             zip.compress(outBuf, inBuf, readLen).then((zipOutInfo) => {
148               console.info(`compress success, status ${zipOutInfo.status}, destLen  ${zipOutInfo.destLen}`);
149               // Write the data in outBuf to the data.bin file.
150               let writeLen = fs.writeSync(outFile.fd, outBuf, { length: zipOutInfo.destLen });
151               console.info(`write destBuf to data.bin, writeLen ${writeLen}`);
152               // Close the file.
153               fs.closeSync(inFile.fd);
154               fs.closeSync(outFile.fd);
155             }).catch((errData: BusinessError) => {
156               console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
157             })
158           }).catch((errData: BusinessError) => {
159             console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
160           })
161         })
162
163         // Example 2: Read the compressed data in the data.bin file and save it to a buffer. Call the uncompress API to decompress the data in the source buffer to the destination buffer and write the content in the destination buffer to the data.txt file.
164         Button('uncompress buffer').onClick(() => {
165           let path = this.getUIContext()?.getHostContext()?.filesDir;
166           let inFile = fs.openSync(path + '/data.bin', fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE);
167           let outFile = fs.openSync(path + '/data.txt', fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE);
168           // Read the compressed data in the data.bin file and save the data to the buffer inBuf.
169           let stat = fs.statSync(inFile.path);
170           let inBuf = new ArrayBuffer(stat.size);
171           let readLen = fs.readSync(inFile.fd, inBuf);
172           console.info(`compressed data size: ${stat.size}, read len: ${readLen}`);
173           // Create a destination buffer. dataSize indicates the original size of the data saved before compression.
174           let outBuf = new ArrayBuffer(this.dataSize);
175           console.info(`the dest buf size is ${this.dataSize}`);
176           // Create a compressed object instance.
177           let zip = zlib.createZipSync();
178           // Decompress the data in inBuf to outBuf.
179           zip.uncompress(outBuf, inBuf, readLen).then((zipOutInfo) => {
180             console.info(`uncompress success, status ${zipOutInfo.status}, destLen  ${zipOutInfo.destLen}`);
181             // Write the data in outBuf to the data.txt file.
182             let writeLen = fs.writeSync(outFile.fd, outBuf, { length: zipOutInfo.destLen });
183             console.info(`write destBuf to data.txt, writeLen ${writeLen}`);
184             // Close the file.
185             fs.closeSync(inFile.fd);
186             fs.closeSync(outFile.fd);
187           }).catch((errData: BusinessError) => {
188             console.error(`errData is errCode:${errData.code}  message:${errData.message}`);
189           })
190         })
191       }
192       .height('100%')
193       .width('100%')
194     }
195   }
196   ```
197
198### Compressing and Decompressing Buffers of Unknown Sizes (.zlib Format)
199
200For data in a buffer with an unknown size, use [deflate()](../../reference/apis-basic-services-kit/js-apis-zlib.md#deflate12) to compress the data read from an original input stream and [inflate()](../../reference/apis-basic-services-kit/js-apis-zlib.md#inflate12) to decompress the data read from a compressed input stream. The sample code is as follows:
201
202   ```ts
203   import { fileIo as fs} from '@kit.CoreFileKit';
204   import { BusinessError, zlib } from '@kit.BasicServicesKit';
205
206   @Entry
207   @Component
208   struct Index {
209     build() {
210       Row() {
211         // Example 1: Continuously read data from a file for compression.
212         Button('deflateFile').onClick(() => {
213           let path = this.getUIContext()?.getHostContext()?.filesDir;
214           let inFile = fs.openSync(path + '/data.txt', fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE);
215           let outFile = fs.openSync(path + '/data.bin', fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE);
216           deflateFile(inFile, outFile).then(() => {
217             console.info('deflateFile success');
218             fs.closeSync(inFile.fd);
219             fs.closeSync(outFile.fd);
220           })
221         })
222
223         // Example 2: Continuously read compressed data from the file for decompression.
224         Button('inflateFile').onClick(() => {
225           let path = this.getUIContext()?.getHostContext()?.filesDir;
226           let inFile = fs.openSync(path + '/data.bin', fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE);
227           let outFile = fs.openSync(path + '/data.txt', fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE);
228           inflateFile(inFile, outFile).then(() => {
229             console.info('deflateFile success');
230             fs.closeSync(inFile.fd);
231             fs.closeSync(outFile.fd);
232           })
233         })
234       }
235       .height('100%')
236       .width('100%')
237     }
238   }
239
240   // Continuously read data from a file, compress the data, and write the data to another file.
241   async function deflateFile(src: fs.File, dest: fs.File) {
242     let flush = zlib.CompressFlushMode.NO_FLUSH;
243     let strm: zlib.ZStream = {};  // Initialize a compression stream.
244     const BUFLEN = 4096;
245     let inBuf = new ArrayBuffer(BUFLEN);  // Initialize an input buffer.
246     let outBuf = new ArrayBuffer(BUFLEN); // Initialize an output buffer.
247     // Create a compressed object instance.
248     let zip = zlib.createZipSync();
249     // Initialize the stream status.
250     let initStatus = zip.deflateInit(strm, zlib.CompressLevel.COMPRESS_LEVEL_BEST_SPEED);
251     console.info('deflateInit ret: ' + (await initStatus).valueOf());
252     do {
253       // Read data from a file to a buffer.
254       let readLen = fs.readSync(src.fd, inBuf);
255       console.info("readSync readLen: " + readLen);
256       flush = readLen == 0 ? zlib.CompressFlushMode.FINISH : zlib.CompressFlushMode.NO_FLUSH;
257       // Set the input buffer.
258       strm.availableIn = readLen;
259       strm.nextIn = inBuf;
260       do {
261         // Set the output buffer.
262         strm.availableOut = BUFLEN;
263         strm.nextOut = outBuf;
264         try {
265           // Compress the data in the input buffer to the output buffer.
266           let deflateStatus = zip.deflate(strm, flush);
267           console.info('deflate ret: ' + (await deflateStatus).valueOf());
268           // Update the stream status.
269           let innerStrm = zip.getZStream();
270           strm.availableIn = (await innerStrm).availableIn;
271           strm.nextIn = (await innerStrm).nextIn;
272           strm.availableOut = (await innerStrm).availableOut;
273           strm.nextOut = (await innerStrm).nextOut;
274           strm.totalIn = (await innerStrm).totalIn;
275           strm.totalOut = (await innerStrm).totalOut;
276
277           if (strm.availableOut != undefined) {
278             // Write the compressed data to the output file.
279             let have = BUFLEN - strm.availableOut;
280             let writeLen = fs.writeSync(dest.fd, outBuf, { length: have });
281             console.info(`writeSync writeLen: ${writeLen}`);
282           }
283         } catch (err) {
284           console.error('deflate err: ' + JSON.stringify(err));
285         }
286       } while (strm.availableOut == 0); // Compress the remaining data in the input buffer cyclically until all data is compressed.
287     } while (flush != zlib.CompressFlushMode.FINISH); // Read data from the file cyclically until all data is read.
288     // Release resources.
289     zip.deflateEnd(strm);
290   }
291
292   // Continuously read compressed data from a file, decompress the data, and write the data to another file.
293   async function inflateFile(src: fs.File, dest: fs.File) {
294     let status: zlib.ReturnStatus = zlib.ReturnStatus.OK;
295     let strm: zlib.ZStream = {};  // Initialize a compression stream.
296     const BUFLEN = 4096;
297     let inBuf = new ArrayBuffer(BUFLEN);  // Initialize an input buffer.
298     let outBuf = new ArrayBuffer(BUFLEN); // Initialize an output buffer.
299     // Create a compressed object instance.
300     let zip = zlib.createZipSync();
301     // Initialize the stream status.
302     let initStatus = zip.inflateInit(strm);
303     console.info('inflateInit ret: ' + (await initStatus).valueOf());
304     do {
305       // Read the compressed data from the file to the buffer.
306       let readLen = fs.readSync(src.fd, inBuf);
307       console.info("readSync readLen: " + readLen);
308       if (readLen == 0) {
309         break;
310       }
311       // Set the input buffer.
312       strm.availableIn = readLen;
313       strm.nextIn = inBuf;
314       do {
315         // Set the output buffer.
316         strm.availableOut = BUFLEN;
317         strm.nextOut = outBuf;
318         try {
319           // Decompress the data in the input buffer to the output buffer.
320           let inflateStatus = zip.inflate(strm, zlib.CompressFlushMode.NO_FLUSH);
321           console.info('inflate ret: ' + (await inflateStatus).valueOf());
322           status = await inflateStatus;
323           // Update the stream status.
324           let innerStrm = zip.getZStream();
325           strm.availableIn = (await innerStrm).availableIn;
326           strm.nextIn = (await innerStrm).nextIn;
327           strm.availableOut = (await innerStrm).availableOut;
328           strm.nextOut = (await innerStrm).nextOut;
329           strm.totalIn = (await innerStrm).totalIn;
330           strm.totalOut = (await innerStrm).totalOut;
331
332           if (strm.availableOut != undefined) {
333             // Write the decompressed data to the output file.
334             let have = BUFLEN - strm.availableOut;
335             let writeLen = fs.writeSync(dest.fd, outBuf, { length: have });
336             console.info(`writeSync writeLen: ${writeLen}`);
337           }
338         } catch (err) {
339           console.error('inflate err: ' + JSON.stringify(err));
340         }
341       } while (strm.availableOut == 0)  // Decompress the remaining data in the input buffer cyclically until all data is decompressed.
342     } while (status != zlib.ReturnStatus.STREAM_END.valueOf())  // Read data from the file cyclically until all data is read.
343     // Release resources.
344     zip.inflateEnd(strm);
345   }
346   ```
347
348### Compressing and Decompressing Buffers of Unknown Sizes (.gzip Format)
349
350For data in a buffer with an unknown size, use [deflate()](../../reference/apis-basic-services-kit/js-apis-zlib.md#deflate12) to compress the data read from an original input stream and [inflate()](../../reference/apis-basic-services-kit/js-apis-zlib.md#inflate12) to decompress the data read from a compressed input stream. The sample code is as follows:
351
352   ```ts
353   import { fileIo as fs} from '@kit.CoreFileKit';
354   import { BusinessError, zlib } from '@kit.BasicServicesKit';
355
356   @Entry
357   @Component
358   struct Index {
359     build() {
360       Row() {
361         // Example 1: Continuously read data from a file for compression.
362         Button('deflateGzipFile').onClick(() => {
363           let path = this.getUIContext()?.getHostContext()?.filesDir;
364           let inFile = fs.openSync(path + '/data.txt', fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE);
365           let outFile = fs.openSync(path + '/data.gz', fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE);
366           deflateGzipFile(inFile, outFile).then(() => {
367             console.info('deflateGzipFile success');
368             fs.closeSync(inFile.fd);
369             fs.closeSync(outFile.fd);
370           })
371         })
372
373         // Example 2: Continuously read compressed data from the file for decompression.
374         Button('inflateGzipFile').onClick(() => {
375           let path = this.getUIContext()?.getHostContext()?.filesDir;
376           let inFile = fs.openSync(path + '/data.gz', fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE);
377           let outFile = fs.openSync(path + '/data.txt', fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE);
378           inflateGzipFile(inFile, outFile).then(() => {
379             console.info('inflateGzipFile success');
380             fs.closeSync(inFile.fd);
381             fs.closeSync(outFile.fd);
382           })
383         })
384       }
385       .height('100%')
386       .width('100%')
387     }
388   }
389
390   // Continuously read data from a file, compress the data, and write the data to another file.
391   async function deflateGzipFile(src: fs.File, dest: fs.File) {
392     let flush = zlib.CompressFlushMode.NO_FLUSH;
393     let strm: zlib.ZStream = {};  // Initialize a compression stream.
394     const BUFLEN = 4096;
395     let inBuf = new ArrayBuffer(BUFLEN);  // Initialize an input buffer.
396     let outBuf = new ArrayBuffer(BUFLEN); // Initialize an output buffer.
397     // Create a compressed object instance.
398     let zip = zlib.createZipSync();
399     // Initialize the stream status. If windowBits is greater than 15, the .gzip format is used.
400     let windowBits = 15 + 16;
401     let initStatus = zip.deflateInit2(strm, zlib.CompressLevel.COMPRESS_LEVEL_BEST_SPEED,
402       zlib.CompressMethod.DEFLATED, windowBits, zlib.MemLevel.MEM_LEVEL_DEFAULT,
403       zlib.CompressStrategy.COMPRESS_STRATEGY_DEFAULT_STRATEGY);
404     console.info('deflateInit2 ret: ' + (await initStatus).valueOf());
405     do {
406       // Read data from a file to a buffer.
407       let readLen = fs.readSync(src.fd, inBuf);
408       console.info("readSync readLen: " + readLen);
409       flush = readLen == 0 ? zlib.CompressFlushMode.FINISH : zlib.CompressFlushMode.NO_FLUSH;
410       // Set the input buffer.
411       strm.availableIn = readLen;
412       strm.nextIn = inBuf;
413       do {
414         // Set the output buffer.
415         strm.availableOut = BUFLEN;
416         strm.nextOut = outBuf;
417         try {
418           // Compress the data in the input buffer to the output buffer.
419           let deflateStatus = zip.deflate(strm, flush);
420           console.info('deflate ret: ' + (await deflateStatus).valueOf());
421           // Update the stream status.
422           let innerStrm = zip.getZStream();
423           strm.availableIn = (await innerStrm).availableIn;
424           strm.nextIn = (await innerStrm).nextIn;
425           strm.availableOut = (await innerStrm).availableOut;
426           strm.nextOut = (await innerStrm).nextOut;
427           strm.totalIn = (await innerStrm).totalIn;
428           strm.totalOut = (await innerStrm).totalOut;
429
430           if (strm.availableOut != undefined) {
431             // Write the compressed data to the output file.
432             let have = BUFLEN - strm.availableOut;
433             let writeLen = fs.writeSync(dest.fd, outBuf, { length: have });
434             console.info(`writeSync writeLen: ${writeLen}`);
435           }
436         } catch (err) {
437           console.error('deflate err: ' + JSON.stringify(err));
438         }
439       } while (strm.availableOut == 0); // Compress the remaining data in the input buffer cyclically until all data is compressed.
440     } while (flush != zlib.CompressFlushMode.FINISH); // Read data from the file cyclically until all data is read.
441     // Release resources.
442     zip.deflateEnd(strm);
443   }
444
445   // Continuously read compressed data from a file, decompress the data, and write the data to another file.
446   async function inflateGzipFile(src: fs.File, dest: fs.File) {
447     let status: zlib.ReturnStatus = zlib.ReturnStatus.OK;
448     let strm: zlib.ZStream = {};  // Initialize a compression stream.
449     const BUFLEN = 4096;
450     let inBuf = new ArrayBuffer(BUFLEN);  // Initialize an input buffer.
451     let outBuf = new ArrayBuffer(BUFLEN); // Initialize an output buffer.
452     // Create a compressed object instance.
453     let zip = zlib.createZipSync();
454     // Initialize the stream status. If windowBits is greater than 15, the .gzip format is used.
455     let windowBits = 15 + 16;
456     let initStatus = zip.inflateInit2(strm, windowBits);
457     console.info('inflateInit2 ret: ' + (await initStatus).valueOf());
458     do {
459       // Read the compressed data from the file to the buffer.
460       let readLen = fs.readSync(src.fd, inBuf);
461       console.info("readSync readLen: " + readLen);
462       if (readLen == 0) {
463         break;
464       }
465       // Set the input buffer.
466       strm.availableIn = readLen;
467       strm.nextIn = inBuf;
468       do {
469         // Set the output buffer.
470         strm.availableOut = BUFLEN;
471         strm.nextOut = outBuf;
472         try {
473           // Decompress the data in the input buffer to the output buffer.
474           let inflateStatus = zip.inflate(strm, zlib.CompressFlushMode.NO_FLUSH);
475           console.info('inflate ret: ' + (await inflateStatus).valueOf());
476           status = await inflateStatus;
477           // Update the stream status.
478           let innerStrm = zip.getZStream();
479           strm.availableIn = (await innerStrm).availableIn;
480           strm.nextIn = (await innerStrm).nextIn;
481           strm.availableOut = (await innerStrm).availableOut;
482           strm.nextOut = (await innerStrm).nextOut;
483           strm.totalIn = (await innerStrm).totalIn;
484           strm.totalOut = (await innerStrm).totalOut;
485
486           if (strm.availableOut != undefined) {
487             // Write the decompressed data to the output file.
488             let have = BUFLEN - strm.availableOut;
489             let writeLen = fs.writeSync(dest.fd, outBuf, { length: have });
490             console.info(`writeSync writeLen: ${writeLen}`);
491           }
492         } catch (err) {
493           console.error('inflate err: ' + JSON.stringify(err));
494         }
495       } while (strm.availableOut == 0)  // Decompress the remaining data in the input buffer cyclically until all data is decompressed.
496     } while (status != zlib.ReturnStatus.STREAM_END.valueOf())  // Read data from the file cyclically until all data is read.
497     // Release resources.
498     zip.inflateEnd(strm);
499   }
500   ```
501
502## FAQs
503
5041. 17800005 Incorrect Input Data
505
506   For details about the possible causes and solution, see [error code 17800005](../../reference/apis-basic-services-kit/errorcode-zlib.md#17800005-incorrect-input-data).
507
5082. 17800007 Incorrect Input Buffer
509
510   For details about the possible causes and solution, see [error code 17800007](../../reference/apis-basic-services-kit/errorcode-zlib.md#17800007-incorrect-input-buffer).
511