Script Library: 1238 scripts
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search

Documentation for: bin-data.r


Using %bin-data.r

Source code originally by Unknown
Usage document written by Brian Tiffin, Library Team apprentice


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

1. Introduction to %bin-data.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-data.r

Another simple one, Just DO it.

Place the script in a directory that you permissions to write files to.

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

From a console session,

>>do %bin-data.r



and REBOL will save an image file, %banner.gif to disk.

3. Filenames in REBOL

Note: REBOL uses % (percent) before a filename, as this is a builtin datatype. The REBOL scanner uses the %banner.gif syntax to "know", deep down "know", that you mean the file 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-data.r holds the %banner.gif file as a base 64 molded binary! 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-save.r shows an example of setting the binary-base.

MakeDoc2 by REBOL- 25-Apr-2007