std/io

Standard Library documentation

Filesystem paths and standard stream helpers.

Module

Name
std/io
Area
Standard Library
Source
modules/std/io.zzm

NAME

std/io - Filesystem paths and standard stream helpers.

SYNOPSIS

  from std/io import Path, STDIN, STDOUT, STDERR;

  let p := new Path("notes.txt");
  p.spew_utf8("hello\n");

  p.each_line( line => {
    STDOUT.print(line);
  } );

IMPLEMENTATION SUPPORT

This module is supported by zuzu.pl, zuzu-rust, and zuzu-js on Node and Electron. It is not supported by zuzu-js in the browser.

DESCRIPTION

This module provides path objects built on path semantics, an iterator for directory traversal, and objects for standard I/O streams.

EXPORTS

Classes

  • Path

    Represents a filesystem path.

    Construction and conversion:

    • new Path(String path = "")
    • to_String

    Path queries and transforms:

    • basename, canonpath, realpath, volume
    • absolute, child, parent, sibling
    • is_absolute, is_relative, is_rootdir
    • subsumes, exists, is_file, is_dir

    Filesystem actions:

    • copy, move, remove, mkdir, mkdir_exclusive,

      remove_tree

      mkdir_exclusive() performs one non-recursive directory creation attempt. It returns true if the directory was created, false if the path already exists, and throws for other filesystem errors.

    • touch, touchpath, chmod
    • size, size_human, stat, lstat

    Text and binary I/O:

    • spew, append, slurp, lines (BinaryString)
    • spew_utf8, append_utf8, slurp_utf8, lines_utf8 (String)
    • spew_async, append_async, slurp_async, lines_async

      return awaitable Task values for binary file I/O

    • spew_utf8_async, append_utf8_async, slurp_utf8_async,

      lines_utf8_async return awaitable Task values for UTF-8 file I/O

    • edit_lines, edit_lines_utf8
    • each_line(callback, raw?) where raw=true yields BinaryString
    • next_line(raw?) where raw=true returns BinaryString

    Traversal helpers:

    • children(...)
    • iterator(...) returning PathIterator
    • visit(callback, ...)

    Static helpers:

    • Path.cwd(), Path.rootdir()
    • Path.tempfile(...), Path.tempdir(...)

      These return Path objects that own the created temporary filesystem entry. The temporary file is deleted when the returned Path object is demolished. Temporary directories and their contents are deleted recursively at the same point. If the Path object is returned or otherwise still referenced, cleanup is deferred until that owning object would normally run __demolish__.

    • Path.glob(pattern, options?)
    • Path.join(parts)
    • Path.split(path)
    • Path.normalize(path)
  • PathIterator

    Directory iterator object with next().

  • STDIN

    Read helpers: next_line(raw?), each_line(callback, raw?). With raw=true, values are BinaryString; otherwise String.

  • STDOUT

    Write helpers: print(...), say(...).

  • STDERR

    Write helpers: print(...), say(...).

COPYRIGHT AND LICENCE

std/io is copyright Toby Inkster.

It is free software; you may redistribute it and/or modify it under the terms of either the Artistic License 1.0 or the GNU General Public License version 2.