Help us shape the future of Go! Take the 2026 Go Developer Survey

fsmod

package
v0.38.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 30, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package fsmod is the native module "fs": directories and files of the local file system (TODO.md Q61).

use fs;
for (local e in fs::readdir(".")) println(e["name"], e["dir"] ? "/" : e["size"]);
fs::walk("src", fn(path, e) { if (fs::ext(path) == ".kkl") println(path); });

An entry is a map: name, size, dir, link, mode and time (a time::Time). What fails is an IOError. Symbolic links are not followed by walk. fs::open gives an fs::File (file.go).

Index

Constants

This section is empty.

Variables

View Source
var File = &native.Class{
	Name: "File",
	Methods: map[string]value.NativeMethod{
		"readline": method("readline", 0, 0, readline),
		"read":     method("read", 0, 1, read),
		"write":    method("write", 1, -1, write),
		"print":    method("print", 0, -1, printer("")),
		"println":  method("println", 0, -1, printer("\n")),
		"seek":     method("seek", 1, 2, seek),
		"tell":     method("tell", 0, 0, tell),
		"truncate": method("truncate", 0, 1, truncate),
		"lock":     method("lock", 0, 2, lock),
		"unlock":   method("unlock", 0, 0, unlock),
		"flush":    method("flush", 0, 0, flush),
		"close":    method("close", 0, 0, closeFile),
		"iter":     method("iter", 0, 0, lines),
		"text":     method("text", 0, 0, text),
		"closed": method("closed", 0, 0, func(a native.Args, env value.Env, f *file) (value.Value, error) {
			return value.MakeBool(f.closed), nil
		}),
		"name": method("name", 0, 0, func(a native.Args, env value.Env, f *file) (value.Value, error) {
			if f.mem != nil {
				return value.NilValue, nil
			}
			return value.MakeString(f.name), nil
		}),
		"mode": method("mode", 0, 0, func(a native.Args, env value.Env, f *file) (value.Value, error) {
			return value.MakeString(f.mode), nil
		}),
	},
	Show: func(o *value.ObjectObj) string {
		f := o.State.(*file)
		switch {
		case f.std != 0:
			return "fs::File(" + f.name + ")"
		case f.mem != nil && f.closed:
			return "fs::File(<memory>, closed)"
		case f.mem != nil:
			return fmt.Sprintf("fs::File(<memory>, %d bytes)", len(f.mem.data))
		case f.closed:
			return fmt.Sprintf("fs::File(%q, closed)", f.name)
		}
		return fmt.Sprintf("fs::File(%q, %q)", f.name, f.mode)
	},
}

File is the class fs::File. It has no constructor: files come from fs::open and the standard streams.

Functions

func ModeString

func ModeString(m fs.FileMode) string

ModeString is mode as ls shows it: "-rw-r--r--", "drwxr-xr-x", "lrwxrwxrwx"; s, S and t, T for setuid, setgid and sticky.

func ParseMode added in v0.34.0

func ParseMode(s string) (fs.FileMode, bool)

ParseMode reads permissions as ModeString writes them: nine letters ("rwxr-x---"), or ten with the kind of file first, which is ignored; s, S, t and T for setuid, setgid and sticky.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL