Error getting tags :
error 404Error getting tags :
error 404 compress | revDocs | RunRev
Welcome Guest (Log in)
Product Edition
Version
compress
Basics
Expander triangle
Type
Function
Syntax

the compress of data

compress(data)

Introduced
1.0
Environment
Desktop, Web and Server
Platform Support
MacOS,Mac OS X,Windows,Linux
Security
None required
Summary
Returns a gzip-compressed string.
Examples

compress(URL "file:image.pict")
put compress(field "Outgoing") into URL "binfile:data.gz"

Additional Comments
Expander triangle

Use the compress function to compress data to a smaller size for transmission.

Parameters:

The data is a string of binary data of any length.

Value:

The compress function returns a string of binary data.

Comments:

The compress function is the inverse of the decompress function.

The compressed result is typically about half to a third the size of the original data, although different results may be obtained depending on the amount of data and whether it has already been compressed.

Important! The value returned by the compressfunction consists of binary data and may include control characters, so displaying it on screen or trying to edit it may produce unexpected results. If you use a URL to place the returned data in a file, it's important to use the binfileURL scheme; using the fileURL scheme will corrupt binary data.

For technical information about the format used by the compress function, see RFC 1952 at <http://www.ietf.org/rfc/rfc1952.txt>. The compress function uses the zlib compression library.

User Comments
Expander triangle
User thumbnail
rjearp@hotmail.com
StarStarStarStarStar
May 18, 2010
The compress function returns a gzip compressed string of binary data structured in the following format:
1) A 10-byte header, containing:
A magic number, composed by two bytes: 1F 8B (Hexadecimal) or 31 139 (ASCII Numbers of both characters)
A version number (always 08), that specify compression compression method used in the file. In this case Rev write the byte 08. This single character correspond to DEFLATE compression.
Additional information like timestamp, optional extra headers, (as the original file name) are not included and in their place Rev writes six null bytes: 00 00 00 00 00 00
Last char of 10 byte header correspond to the type of file system on which compression took place. Rev writes the single byte 03, that correspond to Unix.
For example: First Ten characters of a gzipped binary string (Hexadecimal) 1F 8B 08 00 00 00 00 00 00 03 (ASCII Characters numbers) 31 139 08 00 00 00 00 00 00 03
2- a body, containing DEFLATE-compressed data
3- Last 8 characters contains a CRC-32 checksum and length of the original uncompressed data: For example: Last 8 characters of gzipped binary string (Hexadecimal) 8C 72 E5 F5 1A 34 02 00 Last four bytes: 1A 34 02 00 = 0002341A = 144,410 represent the file length (142 k) Bytes 8C 72 E5 F5 correspond to CRC-32 of this file: F5E5728C
If you need to use only the binary string of DEFLATE-compressed data, without the gzip header and footer, use a script like this:
put compress(myData) into myGzippedData put char 11 to -9 of myGzippedData into myDeflateData
or the short version: put char 11 to -9 of compress(myData) into myDeflateData
This binary string of DEFLATE-compressed data is useful if you need to write a Flate Encoded stream in a PDF file like this:
put "x" & char 11 to -9 of myGzippedData into myFlateEncodedStream