REBOL Document

Write - Function Summary


Summary:

Writes to a file, url, or port-spec (block or object).

Usage:

write destination value

Arguments:

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

value - The value argument.

Refinements:

/binary - Preserves contents exactly.

/string - Translates all line terminators.

/direct - Opens the port without buffering.

/append - Writes to the end of an existing file.

/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)

/allow - Specifies the protection attributes when created.

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

/mode - Block of above refinements.

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

/custom - Allows special refinements.

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

Description:

WRITE is typically used to write a file to disk, but many other operations, such as writing data to URLs and ports, are possible.

Normally a string or binary value is provided to this function, but other types of data such as a number or a time can be written. They will be converted to text.

The /BINARY refinement will write out data as its exact representation. This is good for writing image, sound and other binary data.

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

The /APPEND refinement is useful logging purposes, as it won't overwrite existing data.

The /LINES refinement can take a block of values and will write each value to a line. By default, WRITE will write the block of values as a concatonated string of formed values.

The /PART refinement will read the specified number of elements from the data being written. 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 %junkme.txt "This is a junk file."


    write %datetime.txt now


    write/binary %data compress "this is compressed data"


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


    write/append %rebol-test-file.r "some more text"
    print read %rebol-test-file.r
    some textsome more text


    write %rebol-test-file.r reduce ["the time is:" form now/time]
    print read %rebol-test-file.r
    the time is:1:00:40


    write/lines %rebol-test-file.r reduce ["time is:" form now/time]
    print read %rebol-test-file.r
    time is:
    1:00:40


    write/part %rebol-test-file.r "this is the day!" 7
    print read %rebol-test-file.r
    this is

Related:

close - Closes an open port connection.
form - Converts a value to a string.
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.
read - Reads from a file, url, or port-spec (block or object).
save - Saves a value or a block to a file or url.
set-modes - Changes mode settings for a port.


<Back | Index | Next>

Copyright 2004 REBOL Technologies