REBOL [
    Title:  "Autoextracting REBOL file creator"
    Date:   16-Jun-1999
    Author: "Bohdan Lechnowsky"
    Email:  bo@rebol.com
    File:   %autoextract.r
    Purpose: {
        Send files via email which can be decompressed
        simply by executing the contents of the message when it is
        received.
    }
    Category: [email file util 3]
]

autoextract: func [
    {Compresses a file and puts it into a script 
     which will automatically extract itself}
    infile  [file!] {Name of file to compress}
    outfile [file!] {Name to save compressed file}
][
    file: enbase/base compress read/binary infile 64
    infile: to-file last parse infile "/"

    output: [{Self-extracting REBOL-compressed file
        REBOL [
            Title:  "Self-extracting compressed file"
            Date:  } now {
            File:  } mold infile {
            Author:  "Autoextract function by Bohdan Lechnowsky"
            Comment:  ^{
               Simply run this script and it will 
               decompress and save the file for you
            ^}
        ]

        if exists? } mold infile { [
            print ["} infile { already exists, please rename"
                           " existing file and run again."]
            halt
        ]
        write } mold infile { decompress 64#} mold file
    ]
    write outfile to-string reduce output
]