Interface

# Writeable

<div class="rst-class">

forsearch

</div>

Writing

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

## Description

Provides "specs" for classes with methods which can be used to write data to disk or ports.

## Methods

<div class="rst-class">

table-centered_column_4

</div>

| Name                               | Parameters                               | Returns                            | Shared |
|------------------------------------|------------------------------------------|------------------------------------|--------|
| `Flush<writeable.flush>`           |                                          |                                    |        |
| `Write<writeable.write>`           | text As `String</api/data_types/string>` |                                    |        |
| `WriteError<writeable.writeerror>` |                                          | `Boolean</api/data_types/boolean>` |        |

## Method descriptions

<div id="writeable.flush">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Writeable.Flush

**Flush**

> Immediately sends the contents of internal write buffers to disk or to the output stream.
>
> This function can be useful in point-to-point communication over sockets and similar connections: To optimize for transmission performance, some types of output streams try to collect small pieces of written data into one larger piece for sending instead of sending each piece out individually. By calling Flush, the data collection is stopped and the data is sent without further delay, reducing latency.
>
> When using this on a stream that ends up as a file on disk, it is useful, too: Any short parts of previously written data are written to disk right away, ensuring the data is actually on disk if the application terminates abruptly, e.g. due to a crash.
>
> Avoid calling this method too often. For example, do not call it between successive Write calls because you'll slow down performance without getting much benefit.
>
> A typical use case would look like this:
>
> ``` xojo
> mySocket.Write("you typed: ")
> mySocket.Write(key)
> mySocket.Write(".")
> mySocket.Flush
> ```

<div id="writeable.write">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Writeable.Write

**Write**(text As `String</api/data_types/string>`)

> Writes the passed data to the output stream.
>
> Note that in order to make sure that the data actually ends up on disk or gets sent to the socket it is connected to, the stream must either get closed or the `Flush<writeable.flush>` method be called. Otherwise, the data, if small, may end up temporarily in a write buffer before either a certain time has passed or more data is written. This buffering increases performance when writing lots of small pieces of data, but may be causing unwanted delays when another process, e.g. the other end of a socket connection, is waiting for the data. Consider calling the `Flush<writeable.flush>` method to reduce latencies that this buffering may cause in such cases.
>
> If Write fails, an `IOException</api/exceptions/ioexception>` will be raised.
>
> This example displays the Save As dialog box and writes the contents of the TextArea1 to a text file.
>
> ``` xojo
> Var f As FolderItem
> Var stream As BinaryStream
>
> f = FolderItem.ShowSaveFileDialog(FileTypes1.Text, "Untitled.txt")
>
> If f <> Nil Then
>   stream = BinaryStream.Create(f, True)
>   stream.Write(TextArea1.Text)
>   stream.Close
> End If
> ```

<div id="writeable.writeerror">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Writeable.WriteError

**WriteError** As `Boolean</api/data_types/boolean>`

> If `True</api/language/true>` then an error occurred during writing.

## Notes

The `BinaryStream</api/files/binarystream>`, `IPCSocket</api/networking/ipcsocket>`, `Pop3SecureSocket</api/networking/pop3securesocket>`, `SMTPSecureSocket</api/networking/smtpsecuresocket>`, `SSLSocket</api/networking/sslsocket>`, `SerialConnection</api/hardware/serialconnection>`, `StdErr</api/console/stderr>` and `StdOut</api/console/stdout>` (console applications only), `TCPSocket</api/networking/tcpsocket>`, and `TextOutputStream</api/files/textoutputstream>` provide the <span class="title-ref">Writeable</span> class interface. If you implement this class interface in your application, you must provide the methods with the parameters as shown here.

## Compatibility

|                       |     |
|-----------------------|-----|
| **Project Types**     | All |
| **Operating Systems** | All |

<div class="seealso">

`BinaryStream</api/files/binarystream>`, `IPCSocket</api/networking/ipcsocket>`, `SerialConnection</api/hardware/serialconnection>`, `StdErr</api/console/stderr>`, `StdOut</api/console/stdout>`, `TCPSocket</api/networking/tcpsocket>`, `TextOutputStream</api/files/textoutputstream>` classes; `Readable</api/files/readable>` interface.

</div>
