REBOL Document

Write-io - Function Summary


Summary:

Low level write to a port.

Usage:

write-io port buffer length

Arguments:

port - Already opened port to write to (must be: port)

buffer - Buffer to use for write. (must be: any-string)

length - Maximum number of chars to write (must be: number)

Description:

This function provides a low level method of writing data from a port. For most code, this function should not be used because the INSERT function is the proper method of writing data to a port.

The primary difference between WRITE-IO and INSERT is that WRITE-IO takes a maximum transfer length as one of its arguments. Like the WRITE function of the C language, bytes are transferred from the buffer up to the maximum length specified. The length of the transfer is returned as a result, and it can be zero (for nothing transferred), or even negative in the case of some types of errors.

Here is a simple example of WRITE-IO on a file <B>(Note again: this is a low level IO method; you should normally use the series functions like COPY, INSERT, NEXT, etc. for reading and writing to IO ports.)</B>


    attempt [delete %testfile]
    port: open/direct %testfile
    buffer: "testing"
    write-io port buffer 4
    close port
    probe read %testfile
    "test"

Related:

read-io - Low level read from a port.


<Back | Index | Next>

Copyright 2004 REBOL Technologies