XU XUv0.8.8
中文

API

#io/fs

import: #io/fs

counts: 5 fns, 0 methods, 1 types, 0 consts, 2 ifaces

Directory-tree view. Implementation is concrete os.DirFS; package functions take &os.DirFS. valid_path checks unrooted slash paths.

struct@ FS

XuAPI
struct@ FS {
    fn open(string) os.File
}

Purpose

Method set of fs.FS / fs.File (constraints only; no interface values).

Parameters

open fn open(string) os.File
Method on `FS`: open.

(FS) open

XuAPI
fn open(string) os.File

Purpose

Method on `FS`: open.

Parameters

self Self
receiver Self (value receiver)
string string
string (string)

Returns

os.File — a value of this type

struct@ File

XuAPI
struct@ File {
    fn read(int) string
    fn close() int
}

Purpose

Method-set constraint `File`. Implementing types must provide the methods below. Not an interface value.

Parameters

read fn read(int) string
Method on `File`: read up to max bytes.
close fn close() int
Method on `File`: close the resource.

(File) read

XuAPI
fn read(int) string

Purpose

Method on `File`: read up to max bytes.

Parameters

self Self
receiver Self (value receiver)
int int
int (int)

Returns

string — result string

(File) close

XuAPI
fn close() int

Purpose

Method on `File`: close the resource.

Parameters

self Self
receiver Self (value receiver)

Returns

int — a value of this type

struct DirEntry

XuAPI
pub struct DirEntry {
    pub name string
    pub is_dir bool
}

Purpose

FileInfo is the language builtin (: size / is_dir / mode), same as os.Stat — fs.FileInfo.Name is path.base of the lookup name.

Parameters

name string
name
is_dir bool
field (bool)

valid_path

XuAPI
pub fn valid_path(name &string) bool

Purpose

valid_path is fs.ValidPath: unrooted slash-separated name; "." is the only allowed "." / empty / ".." exception (the FS root).

Parameters

name &string
name (borrowed; caller keeps it; type &string)

Returns

bool — true or false

read_file

XuAPI
pub fn read_file(fsys &os.DirFS, name string) string

Purpose

Read file. Throws on failure.

Parameters

fsys &os.DirFS
fsys (borrowed; caller keeps it; type &os.DirFS)
name string
name (string)

Returns

string — result string

read_dir

XuAPI
pub fn read_dir(fsys &os.DirFS, name string) []DirEntry

Purpose

Read directory. Throws on failure.

Parameters

fsys &os.DirFS
fsys (borrowed; caller keeps it; type &os.DirFS)
name string
name (string)

Returns

[]DirEntry — slice result

stat

XuAPI
pub fn stat(fsys &os.DirFS, name string) FileInfo

Purpose

Read metadata. Throws on failure.

Parameters

fsys &os.DirFS
fsys (borrowed; caller keeps it; type &os.DirFS)
name string
name (string)

Returns

FileInfo — a value of this type

sub

XuAPI
pub fn sub(fsys &os.DirFS, dir string) os.DirFS

Purpose

Subtract. Throws on failure.

Parameters

fsys &os.DirFS
fsys (borrowed; caller keeps it; type &os.DirFS)
dir string
directory (string)

Returns

os.DirFS — a value of this type