# Method Gz.compress()

Method compress

  ``string(8bit)` compress(`string(8bit)`|`String.Buffer`|`System.Memory`|`Stdio.Buffer` `data`, `void`|`bool` `raw`, `void`|`int(0..9)` `level`, `void`|`int` `strategy`, `void`|`int(8..15)` `window_size`)`

Description

  Encodes and returns the input `data` according to the deflate format defined in RFC 1951.

Parameter `data`

  The data to be encoded.

Parameter `raw`

  If set, the data is encoded without the header and footer defined in RFC 1950. Example of uses is the ZIP container format.

Parameter `level`

  Indicates the level of effort spent to make the data compress well. Zero means no packing, 2-3 is considered 'fast', 6 is default and higher is considered 'slow' but gives better packing.

Parameter `strategy`

  The strategy to be used when compressing the data. One of the following.

  ``DEFAULT_STRATEGY`` | The default strategy as selected in the zlib library.
  ``FILTERED`` | This strategy is intented for data created by a filter or predictor and will put more emphasis on huffman encoding and less on LZ string matching. This is between DEFAULT_STRATEGY and HUFFMAN_ONLY.
  ``RLE`` | This strategy is even closer to the HUFFMAN_ONLY in that it only looks at the latest byte in the window, i.e. a window size of 1 byte is sufficient for decompression. This mode is not available in all zlib versions.
  ``HUFFMAN_ONLY`` | This strategy will turn of string matching completely, only doing huffman encoding. Window size doesn't matter in this mode and the data can be decompressed with a zero size window.
  ``FIXED`` | In this mode dynamic huffman codes are disabled, allowing for a simpler decoder for special applications. This mode is not available in all zlib versions.

Parameter `window_size`

  Defines the size of the LZ77 window from 256 bytes to 32768 bytes, expressed as 2^x.

See also

  deflate, inflate, uncompress