Skip to content

io.fs #

io.fs

io.fs defines small filesystem interfaces that can be shared by different backends and virtual filesystems.

The module is modeled after Go's io/fs package, but follows V naming and type conventions.

Current helpers:

  • valid_path(name string) bool
  • read_file(filesystem FS, name string) ![]u8
  • read_dir(filesystem FS, name string) ![]DirEntry
  • stat(filesystem FS, name string) !FileInfo
  • file_info_to_dir_entry(info FileInfo) DirEntry

fn file_info_to_dir_entry #

fn file_info_to_dir_entry(info FileInfo) DirEntry

file_info_to_dir_entry wraps a FileInfo in a DirEntry.

fn read_dir #

fn read_dir(filesystem FS, name string) ![]DirEntry

read_dir reads and sorts the named directory from filesystem.

fn read_file #

fn read_file(filesystem FS, name string) ![]u8

read_file reads the named file from filesystem.

fn stat #

fn stat(filesystem FS, name string) !FileInfo

stat returns file information for the named path from filesystem.

fn valid_path #

fn valid_path(name string) bool

valid_path reports whether name is a valid slash-separated path for FS.open.

interface DirEntry #

interface DirEntry {
	name() string
	is_dir() bool
	typ() os.FileType
	info() !FileInfo
}

DirEntry describes a single directory entry.

interface FS #

interface FS {
	open(name string) !File
}

FS opens slash-separated paths that pass valid_path.

interface File #

interface File {
	io.Reader
	stat() !FileInfo
mut:
	close()
}

File is the minimum interface required to read from a filesystem entry.

interface FileInfo #

interface FileInfo {
	name() string
	size() u64
	mode() os.FileMode
	mod_time() i64
	is_dir() bool
}

FileInfo describes a file or directory entry.

interface GlobFS #

interface GlobFS {
	glob(pattern string) ![]string
}

GlobFS can expand glob patterns within a filesystem.

interface ReadDirFS #

interface ReadDirFS {
	read_dir(name string) ![]DirEntry
}

ReadDirFS can read a directory without first opening it as a File.

interface ReadDirFile #

interface ReadDirFile {
	File
mut:
	read_dir(n int) ![]DirEntry
}

ReadDirFile can read directory entries directly from an opened file.

interface ReadFileFS #

interface ReadFileFS {
	read_file(name string) ![]u8
}

ReadFileFS can read a whole file without first opening it as a File.

interface StatFS #

interface StatFS {
	stat(name string) !FileInfo
}

StatFS can stat a path without first opening it as a File.

interface SubFS #

interface SubFS {
	sub(dir string) !FS
}

SubFS can return a filesystem rooted at a subdirectory.