← Back to the index

Module std/fs/file.vv

The fs/file module provides low-level file I/O operations.

Example:

import file from "std/fs/file.vv"

let fd = try file.create("test.txt")
defer file.close(fd)
try file.write(fd, "hello")

Table of Contents

Exports

fun open(path, is_append) extern "native"

Opens a file in read and write mode.

  • path: The path to the file.
  • is_append: If true, opens the file in append mode.

Returns the file descriptor (fd).

fun open_read(path) extern "native"

Opens a file in read-only mode.

  • path: The path to the file.

Returns the file descriptor (fd).

fun open_write(path, is_append) extern "native"

Opens a file in write-only mode.

  • path: The path to the file.
  • is_append: If true, opens the file in append mode.

Returns the file descriptor (fd).

fun create(path) extern "native"

Creates a new file.

  • path: The path to the file.

Returns the file descriptor (fd).

fun exists(path) extern "native"

Checks if a file exists.

  • path: The path to the file.

Returns a boolean indicating if the file exists.

fun close(fd) extern "native"

Closes a file descriptor.

  • fd: The file descriptor to close.

fun read(fd, length) extern "native"

Reads bytes from a file.

  • fd: The file descriptor to read from.
  • length: The number of bytes to read.

Returns the read content as a list of integers (bytes).

fun write(fd, content) extern "native"

Writes bytes to a file.

  • fd: The file descriptor to write to.
  • content: The bytes (list of integers or characters) to write.

Returns the number of bytes written.

fun remove(path) extern "native"

Removes a file.

  • path: The path to the file.

fun reader(path)

Creates a generalized reader stream for a file.

  • path: The path to the file.

Returns a record with fd, read, and close functions.

fun writer(path, is_append)

Creates a generalized writer stream for a file.

  • path: The path to the file.
  • is_append: If true, opens the file in append mode.

Returns a record with fd, write, and close functions.