REBOL 3 Docs | Guide | Concepts | Functions | Datatypes | Errors |
TOC < Back Next > | Updated: 3-Aug-2010 Edit History |
Decompresses data. Result is binary.
Arguments:
data [binary!] - Data to decompress
Refinements:
/limit
size - Limit the result to this maximum size
See also:
Examples:
write %file.txt read http://www.rebol.net
size? %file.txt
5539
save %file.comp compress read %file.txt
size? %file.comp
2119
write %file.decomp decompress load %file.comp
size? %file.decomp
5539
If the data passed to the decompress function has been altered or corrupted, a decompression error will occur.
A typical error is out of memory, if the decompressed file length appears to be wrong (perhaps several gigabytes instead of 5539 bytes) to decompress.
Using the /limit refinement, puts a hard limit to the size of the decompressed file:
decompress/limit read %file.comp 5000 ** Script error: maximum limit reached: 5539 ** Where: decompress ** Near: decompress/limit read %file.comp 5000
This can help avoiding that a decompress operation on a corrupt file suddenly eats all system resources.
decompress can decompress any ZLIB data as long as the data has the length of the uncompressed data in binary little-endian representation appended:
zlib-decompress: func [ zlib-data [binary!] length [integer!] "known uncompressed zlib data length" ][ decompress head insert tail zlib-data third make struct! [value [integer!]] reduce [length] ]
TOC < Back Next > | REBOL.com - WIP Wiki | Feedback Admin |