Documention for: oneliner-gzip.r3
Created by: vincentecuye
on: 30-Jan-2013
Last updated by: vincentecuye on: 30-Jan-2013
Format: html
Downloaded on: 18-Apr-2024

REBOL

oneliner-gzip.r3

Author: Vincent Ecuyer
Date: 30-Jan-2013

Contents:

1. Purpose
2. Limitations
3. Usage
4. Example
5. Commented Code

1. Purpose

Creates gzip compatible archives.

2. Limitations

To keep the code short, a number of gzip files optional capabilities aren't implemented:

  • REBOL 3 only
  • No filename in archive (optional : gzip tools assumes the filename is the same as the source without the .gz extension)
  • No timestamp in archive (not a big problem with .tar archive, as tar and gzip are often used together)

3. Usage

gzip value (binary!)

4. Example

write %test.tar.gz gzip read/binary %test.tar

5. Commented Code

gzip: func [
    "Compresses a binary and returns it in gzip format"
    value [binary!] "Data to compress"
][
    ; In a gzip file, the last four bytes holds the data size, 
    ; and the four bytes before holds the crc32.

    ; 'compress uses another crc method,
    ; so the crc bytes must be replaced 

    ; replaces the crc by a crc32:
    head change at tail 
        ; joins a gzip header to a 'compress stream,
        ; skipping the 'compress zlib header (2 bytes)
        join #{1F8B08000000000002FF} skip compress value 2

        ; "at tail data -8" means at 8 bytes before the end of the data
        -8

        ; builds a four bytes value with the crc-32 in little endian order
        ; ('to-binary on an integer! gives a 8 bytes result)
        reverse skip to-binary checksum/method value 'crc32 4
]
MakeDoc2 by REBOL - 30-Jan-2013