REBOL 3 Docs Guide Concepts Functions Datatypes Errors
  TOC < Back Next >   Updated: 3-Aug-2010 Edit History  

REBOL 3 Functions: decompress

decompress  data  /limit  size

Decompresses data. Result is binary.


data [binary!] - Data to decompress



size - Limit the result to this maximum size

See also:

compress   enbase   debase  



write %file.txt read
size? %file.txt
save %file.comp compress read %file.txt
size? %file.comp
write %file.decomp decompress load %file.comp
size? %file.decomp

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.

Special Notes

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 > - WIP Wiki Feedback Admin