Io module

writer_of

procedure · 3 overloadsSource

The file as a Writer. Writing advances the file's position. The writer points at the Io_File, which must outlive it.

writer_of :: (file: *Io_File) -> Writer

The file as a Writer. Writing advances the file's position. The writer points at the Io_File, which must outlive it.

Parameters

file: *Io_File

Returns

writer_of :: (stream: Tcp_Stream) -> Writer

The TCP stream as a Writer. write through it waits as long as it takes for the peer to take the bytes. Closing the writer closes the stream.

Parameters

stream: Tcp_Stream

Returns

Example
Io :: #import "Extensions/Io";

main :: () {
    Io.io_run(() {
        listener, _ := Io.tcp_listen("127.0.0.1:0");
        defer Io.close(listener);

        address, _ := Io.local_address(listener);
        client, _ := Io.connect(address);
        server, _ := Io.accept(listener);

        Io.write(Io.writer_of(client), "hello");

        buffer: [8] u8;
        count, error := Io.read(Io.reader_of(server), buffer);
        assert(error == .NONE && string.{ count, buffer.data } == "hello");

        Io.close(client);
        Io.close(server);
    });
}

Doesn't run in the browser (skipped on wasm).

writer_of :: (stream: *Pipe_Stream) -> Writer

One end of a pipe from make_pipe as a Writer. The writer points at the pipe end, which must outlive it.

Parameters

stream: *Pipe_Stream

Returns

See also