A FileWr.T
, or file writer, is a writer on a File.T
.
\index{buffered file I/O}
\index{file!buffered I/O}
INTERFACEFileWr ; IMPORT Wr, File, OSError, Pathname; TYPE T <: Public; Public = Wr.T OBJECT METHODS init(h: File.T; buffered: BOOLEAN := TRUE): T RAISES {OSError.E} END;
Ifw
is a file writer andh
is a file handle, the callw.init(h)
initializesw
so that characters output tow
are written toh
and so that closingw
closesh
.
If
h
is a regular file handle and b
is a Boolean, w.init(h, b)
causes w
to be a buffered seekable writer and initializes cur(w)
to cur(h)
.
For any other file handle h
, w.init(h, b)
causes w
to be
a nonseekable writer, buffered if and only if b
is TRUE
, and
initializes cur(w)
to zero.
If a subsequent writer operation on w
raises Wr.Failure
, the
associated exception argument is the AtomList.T
argument
accompanying an OSError.E
exception from a file operation on h
.
PROCEDURE Open(p: Pathname.T): T RAISES {OSError.E};
Return a file writer whose target is the file named p
. If the
file does not exist, it is created. If the file exists, it is
truncated to a size of zero.
The call
Open(p)
is equivalent to the following:
RETURN NEW(T).init(FS.OpenFile(p))
PROCEDURE OpenAppend(p: Pathname.T): T RAISES {OSError.E};
Return a file writer whose target is the file named p
. If the
file does not exist, it is created. If the file exists, the writer is
positioned to append to the existing contents of the file.
The call
OpenAppend(p)
is equivalent to the following:
WITH h = FS.OpenFile(p, truncate := FALSE) DO EVAL h.seek(RegularFile.Origin.End, 0); RETURN NEW(T).init(h) END
END FileWr.