Search results

There are no results.

std.fs.file.WriteOnlyFile

class pub WriteOnlyFile

A file that can only be used for writes.

Fields

path

let pub @path: Path

The path of the file.

Static methods

append

Show source code
Hide source code
fn pub static append(path: Path) -> Result[WriteOnlyFile, Error] {
  match inko_file_open(_INKO.process, path.to_string, FILE_APPEND_ONLY) {
    case { @tag = 0, @value = v } -> {
      Result.Ok(WriteOnlyFile(path: path, fd: v))
    }
    case { @tag = _, @value = e } -> {
      Result.Error(Error.from_os_error(e as Int))
    }
  }
}
fn pub static append(path: Path) -> Result[WriteOnlyFile, Error]

Opens a file in append-only mode.

Examples

import std.fs.file (WriteOnlyFile)

let file = WriteOnlyFile.append('/dev/null'.to_path).get

new

Show source code
Hide source code
fn pub static new(path: Path) -> Result[WriteOnlyFile, Error] {
  match inko_file_open(_INKO.process, path.to_string, FILE_WRITE_ONLY) {
    case { @tag = 0, @value = v } -> {
      Result.Ok(WriteOnlyFile(path: path, fd: v))
    }
    case { @tag = _, @value = e } -> {
      Result.Error(Error.from_os_error(e as Int))
    }
  }
}
fn pub static new(path: Path) -> Result[WriteOnlyFile, Error]

Opens a file in write-only mode.

Examples

import std.fs.file (WriteOnlyFile)

let file = WriteOnlyFile.new('/dev/null'.to_path).get

Instance methods

flush

Show source code
Hide source code
fn pub mut flush -> Result[Nil, Error] {
  match inko_file_flush(_INKO.process, @fd) {
    case { @tag = 1, @value = _ } -> Result.Ok(nil)
    case { @tag = _, @value = e } -> {
      Result.Error(Error.from_os_error(e as Int))
    }
  }
}
fn pub mut flush -> Result[Nil, Error]

Flushes any pending writes.

print

Show source code
Hide source code
fn pub mut print(string: String) -> Result[Nil, Error] {
  write_string(string).then(fn (_) { write_string('\n') })
}
fn pub mut print(string: String) -> Result[Nil, Error]

Writes the entirety of string to the underlying stream, followed by writing a Unix newline to the stream.

seek

Show source code
Hide source code
fn pub mut seek(position: Int) -> Result[Int, Error] {
  match inko_file_seek(_INKO.process, @fd, position) {
    case { @tag = 0, @value = v } -> Result.Ok(v)
    case { @tag = _, @value = e } -> Result.Error(Error.from_os_error(e))
  }
}
fn pub mut seek(position: Int) -> Result[Int, Error]

Seeks to the given byte offset, returning the new offset.

If position is negative, seeking is performed in reverse order relative to the end.

write_bytes

Show source code
Hide source code
fn pub mut write_bytes(bytes: ref ByteArray) -> Result[Nil, Error] {
  write_all_internal(bytes.to_pointer, bytes.size)
}
fn pub mut write_bytes(bytes: ref ByteArray) -> Result[Nil, Error]

Writes the entirety of bytes to the underlying stream.

Types implementing this method must guarantee that upon returning from this method, either all of the data is written and a Ok(Nil) is returned, or an Error(Error) is returned.

write_string

Show source code
Hide source code
fn pub mut write_string(string: String) -> Result[Nil, Error] {
  write_all_internal(string.to_pointer, string.size)
}
fn pub mut write_string(string: String) -> Result[Nil, Error]

Writes the entirety of string to the underlying stream.

See Write.write_bytes for more details.

Implemented traits

std.drop.

Drop

impl Drop for WriteOnlyFile
std.io.

Seek

impl Seek for WriteOnlyFile
std.io.

Write

impl Write for WriteOnlyFile