Documention for: bin-save.r
Created by: btiffin
on: 25-Apr-2007
Last updated by: btiffin on: 25-Apr-2007
Format: html
Downloaded on: 28-Mar-2024

REBOL

Using %bin-save.r

Source code originally by Unknown
Usage document written by Brian Tiffin, Library Team apprentice
24-Apr-2007

Contents:

1. Introduction to %bin-save.r
2. Using %bin-save.r
3. Filenames in REBOL
4. system/options/binary-base

1. Introduction to %bin-save.r

Another script that is more for reading and learning than running.

This example highlights REBOL's power of datatyping. In this case the binary! data type, or more specifically a MOLDed binary!,

Unlike other programming enironments, you can "see" a binary! as a editable string, once molded, and REBOL can load and save data in this form.

REBOL lets you include data, right in the source, that would be near impossible to use an editor with in other environments.

This script needs to be scanned, and then executed for full appreciation.

2. Using %bin-save.r

Another simple one, Just DO it. Well, not quite, there is a little setup for this one.

Place the script in a directory that you permissions to write files to, and includes an image file, named %rebol-banner.gif If you don't have %rebol-banner.gif, run the sister script to this one, %bin-data.r to create %banner.gif and then

>>rename %banner.gif %rebol-banner.gif

Start up REBOL with the -s option, or answer Yes or All to the security dialog.

From a console session,

>>do %bin-save.r

or

>>do http://www.rebol.org/cgi-bin/cgiwrap/rebol/download-a-script.r?script-name=bin-save.r

and REBOL will save a molded string from the image file, %rebol-banner.gif to disk as readable REBOL code, in %banner.r. This file can then be cut and pasted into a script, or left as a simple datafile.

3. Filenames in REBOL

Note: REBOL uses % (percent) before a filename, as this is a builtin datatype. The REBOL scanner uses the %rebol-banner.gif syntax to "know", deep down "know", that you mean the file rebol-banner.gif.

This may seem a little strange at first, but you'll be slinging filenames around using the percent syntax, before you know it.

4. system/options/binary-base

The REBOL system object an internal control variable that controls the numeric base for binary! molding and conversion.

%bin-save.r holds the %banner.r file as a base 64 molded binary! or %rebol-banner.gif. By default, REBOL uses a system/options/binary-base value of 16. The binary! would then mold to a hexadecimal string.

Base 64, packs more binary! into the string version as it can use more symbols to represent values.

Common values for system/options/binary-base are 64, 16, and 2. The default of 16 is usually fine, unless you really want to shrink down included string forms of binary data.

The sister script to this one, %bin-data.r shows an example of a binary-base 64 molded binary string.

MakeDoc2 by REBOL - 25-Apr-2007