files

package
v1.20.0 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package files provides file I/O primitives.

Textual File I/O (R7RS 6.13.1)

  • open-input-file, open-output-file
  • call-with-input-file, call-with-output-file
  • with-input-from-file, with-output-to-file

Binary File I/O

  • open-binary-input-file, open-binary-output-file

File Predicates

  • file-exists?, delete-file

Directory Operations (SRFI-170)

  • create-directory, delete-directory, directory-files
  • current-directory, set-current-directory!

Use Extension or AddToRegistry to register all primitives.

Index

Constants

This section is empty.

Variables

View Source
var AddToRegistry = Builder.AddToRegistry

AddToRegistry registers all file primitives.

View Source
var Builder = registry.NewRegistryBuilder(addPrimitives, addMacros)

Builder aggregates all file registration functions.

View Source
var Extension = registry.NewDescribedExtension("files",
	"Filesystem operations: file I/O, directory creation/listing, working directory.",
	AddToRegistry)

Extension is the file I/O extension.

Functions

func PrimCallWithInputFile

func PrimCallWithInputFile(cc machine.CallContext) error

PrimCallWithInputFile implements the call-with-input-file primitive.

func PrimCallWithOutputFile

func PrimCallWithOutputFile(cc machine.CallContext) error

PrimCallWithOutputFile implements the call-with-output-file primitive.

func PrimCreateDirectory added in v1.9.1

func PrimCreateDirectory(mc machine.CallContext) error

PrimCreateDirectory implements the (create-directory) primitive. Creates a single directory level. Errors if it already exists or the parent is missing (no recursive mkdir -p behavior).

func PrimCurrentDirectory added in v1.9.1

func PrimCurrentDirectory(mc machine.CallContext) error

PrimCurrentDirectory implements the (current-directory) primitive. Returns the current working directory as a string.

func PrimDeleteDirectory added in v1.9.1

func PrimDeleteDirectory(mc machine.CallContext) error

PrimDeleteDirectory implements the (delete-directory) primitive. Removes an empty directory. Errors if not empty, nonexistent, or not a directory.

func PrimDeleteFile

func PrimDeleteFile(mc machine.CallContext) error

PrimDeleteFile implements the (delete-file) primitive. Deletes a file from the filesystem.

func PrimDirectoryFiles added in v1.9.1

func PrimDirectoryFiles(mc machine.CallContext) error

PrimDirectoryFiles implements the (directory-files) primitive. Returns a list of filename strings in the directory, excluding "." and "..". Names are filenames only (not full paths).

func PrimFileExistsQ

func PrimFileExistsQ(mc machine.CallContext) error

PrimFileExistsQ implements the (file-exists?) primitive. Returns #t if the file exists and this engine is permitted to see it.

DENIAL AND ABSENCE ARE DELIBERATELY INDISTINGUISHABLE. A path the authorizer refuses, and a path the OS refuses to stat, both answer #f — the same answer a path that is not there gets. That is not a rounding error to be fixed back: R7RS §6.14 gives this procedure a boolean and no error clause, an authorizer violation does not present itself as an error (it stays in the authorizer's domain and escapes to the host that installed it, not to the sandboxed program), and a predicate that distinguished the two would hand a sandboxed program an oracle for the filesystem outside its sandbox. A caller that needs to know WHY is not served by this procedure; a lower-level call that reports the reason is anticipated and is not built here.

The refusals are not the whole error space. A system error that carries no information about existence — EIO, ELOOP, ENAMETOOLONG, a timeout — raises, because reporting it as #f would claim the file is absent on evidence that says nothing of the kind. See statAnswersFalse for where the line falls.

func PrimOpenBinaryInputFile

func PrimOpenBinaryInputFile(mc machine.CallContext) error

PrimOpenBinaryInputFile implements the open-binary-input-file primitive (R7RS). Opens a file for binary reading and returns a binary input port.

func PrimOpenBinaryOutputFile

func PrimOpenBinaryOutputFile(mc machine.CallContext) error

PrimOpenBinaryOutputFile implements the open-binary-output-file primitive (R7RS). Opens a file for binary writing and returns a binary output port.

func PrimOpenInputFile

func PrimOpenInputFile(mc machine.CallContext) error

PrimOpenInputFile implements the open-input-file primitive. Opens a file for reading and returns an input port.

func PrimOpenOutputFile

func PrimOpenOutputFile(mc machine.CallContext) error

PrimOpenOutputFile implements the open-output-file primitive. Opens a file for writing and returns an output port.

func PrimSetCurrentDirectory added in v1.9.1

func PrimSetCurrentDirectory(mc machine.CallContext) error

PrimSetCurrentDirectory implements the (set-current-directory!) primitive.

WARNING: os.Chdir is process-global. Multiple engines in the same Go process share a single working directory. Concurrent calls from different goroutines race on the same OS state. This is inherent to POSIX — there is no per-thread working directory.

Types

This section is empty.

Jump to

Keyboard shortcuts

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