REBOL 3 Docs Guide Concepts Functions Datatypes Errors
  TOC < Back Next >   Updated: 3-Aug-2010 Edit History  

REBOL 3 Functions: write

write  destination  data  /part  length  /seek  index  /append  /allow  access  /lines

Writes to a file, URL, or other port - auto-converts text strings.

Arguments:

destination [port! file! url! block!]

data [binary! string! block!] - Data to write (non-binary converts to UTF-8)

Refinements:

/part - Partial write a given number of units

length [number!]

/seek - Write at a specific position

index [number!]

/append - Write data at end of file

/allow - Specifies protection attributes

access [block!]

/lines - Write each value in a block as a separate line

See also:

read   open   close   load   save   form  

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
write %datetime.txt now
write
write/binary %data compress "this is compressed data"

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

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

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


  TOC < Back Next > REBOL.com - WIP Wiki Feedback Admin