REBOL Document

Read - Function Summary


Reads from a file, url, or port-spec (block or object).


read source


source - The source argument. (must be: file url object block)


/binary - Preserves contents exactly.

/string - Translates all line terminators.

/direct - Opens the port without buffering.

/no-wait - Returns immediately without waiting if no data.

/lines - Handles data as lines.

/part - Reads a specified amount of data.

size - The size argument. (must be: number)

/with - Specifies alternate line termination.

end-of-line - The end-of-line argument. (must be: char string)

/mode - Block of above refinements.

args - The args argument. (must be: block)

/custom - Allows special refinements.

params - The params argument. (must be: block)

/skip - Skips a number of bytes.

length - The length argument. (must be: number)


Using READ is the simplest way to get information from a file or URL. This is a higher level port operation that opens a port, reads some or all of the data, then closes the port and returns the data that was read. When used on a file, or URL, the contents of the file, or URL are returned as a string.

The /BINARY refinement forces READ to do a binary read. When used on a text file, line terminators will not be converted.

The /STRING refinement translates line terminators to the operating system's line terminator. This behavior is default.

The /DIRECT refinement reads without buffering, useful for reading files too large to contain in memory.

The /LINES refinement returns read content as a series of lines. One line is created for each line terminator found in the read data.

The /PART refinement reads the specified number of elements from the file, URL, or port. Reading a file or URL will read the specified number of characters. Used with /LINES, it reads a specified number of lines.

The /WITH refinement converts characters, or strings, specified into line terminators.

See the User's Guide for more detailed explanation of using READ and its refinements.

    write %rebol-test-file.r "text file"
    print read %rebol-test-file.r
    text file

    write %rebol-test-file.r [
    {A learned blockhead is a greater man
    than an ignorant blockhead.
          -- Rooseveldt Franklin}
    probe first read/lines %rebol-test-file.r
    "A learned blockhead is a greater man"

    probe pick (read/lines %rebol-test-file.r) 3
    "          -- Rooseveldt Franklin"

    probe read/part %rebol-test-file.r 9
    "A learned"

    probe read/with %rebol-test-file.r "blockhead"
    {A learned 
     is a greater man^M
        than an ignorant 
              -- Rooseveldt Franklin}


close - Closes an open port connection.
get-modes - Returns mode settings for a port.
load - Loads a file, URL, or string. Binds words to global context.
open - Opens a new port connection.
save - Saves a value or a block to a file or url.
set-modes - Changes mode settings for a port.
write - Writes to a file, url, or port-spec (block or object).

<Back | Index | Next>

Copyright 2004 REBOL Technologies