|
| 1 | +\page DECOMPRESS DECOMPRESS Function |
| 2 | + |
| 3 | +```basic id="w4kp6f" |
| 4 | +DECOMPRESS(input, input_len, output, output_max_len) |
| 5 | +``` |
| 6 | + |
| 7 | +Decompresses a gzip-compressed memory buffer. |
| 8 | + |
| 9 | +Decompressed data is written to the output buffer and the function returns the decompressed size in bytes. |
| 10 | + |
| 11 | +Returns zero on error. |
| 12 | + |
| 13 | +--- |
| 14 | + |
| 15 | +### Examples |
| 16 | + |
| 17 | +```basic id="m7qz6a" |
| 18 | +REM Decompress a gzip-compressed memory buffer |
| 19 | +
|
| 20 | +INPUT_BUFFER = MEMALLOC(1024) |
| 21 | +OUTPUT_BUFFER = MEMALLOC(8192) |
| 22 | +
|
| 23 | +REM Fill compressed input buffer here |
| 24 | +
|
| 25 | +SIZE = DECOMPRESS(INPUT_BUFFER, 1024, OUTPUT_BUFFER, 8192) |
| 26 | +
|
| 27 | +PRINT "Decompressed size: "; SIZE |
| 28 | +``` |
| 29 | + |
| 30 | +```basic id="j0x2vq" |
| 31 | +REM Load and decompress a gzip file |
| 32 | +
|
| 33 | +F = OPENIN("archive.gz") |
| 34 | +
|
| 35 | +COMPRESSED_SIZE = FILESIZE("archive.gz") |
| 36 | +
|
| 37 | +COMPRESSED = MEMALLOC(COMPRESSED_SIZE) |
| 38 | +OUTPUT = MEMALLOC(65536) |
| 39 | +
|
| 40 | +BINREAD F, COMPRESSED, COMPRESSED_SIZE |
| 41 | +CLOSE F |
| 42 | +
|
| 43 | +SIZE = DECOMPRESS(COMPRESSED, COMPRESSED_SIZE, OUTPUT, 65536) |
| 44 | +
|
| 45 | +PRINT "Decompressed "; COMPRESSED_SIZE; " bytes into "; SIZE |
| 46 | +``` |
| 47 | + |
| 48 | +--- |
| 49 | + |
| 50 | +### Notes |
| 51 | + |
| 52 | +* `input` is the compressed source memory buffer. |
| 53 | +* `input_len` is the compressed input size in bytes. |
| 54 | +* `output` is the destination memory buffer. |
| 55 | +* `output_max_len` is the maximum writable size of the output buffer. |
| 56 | +* The output buffer must be large enough to hold the decompressed data. |
| 57 | +* Returns the decompressed size in bytes. |
| 58 | +* Returns zero if decompression fails. |
| 59 | + |
| 60 | +--- |
| 61 | + |
| 62 | +### Errors |
| 63 | + |
| 64 | +* Decompression failed |
| 65 | +* Output buffer too small |
| 66 | + |
| 67 | +--- |
| 68 | + |
| 69 | +**See also:** |
| 70 | +\ref COMPRESS "COMPRESS" · \ref MEMALLOC "MEMALLOC" · \ref MEMRELEASE "MEMRELEASE" · \ref BINREAD "BINREAD" · \ref BINWRITE "BINWRITE" |
| 71 | + |
0 commit comments