BinIO
structure
signature BIN_IO
structure BinIO
:> BIN_IO
The structure BinIO
provides input/output of binary data (8-bit bytes). The semantics of the various I/O operations can be found in the description of the IMPERATIVE_IO
signature. The openIn
and openOut
functions allow the creation of binary streams to read and write file data. Certain implementations may provide other ways to open files in structures specific to an operating system.
include IMPERATIVE_IO
where type StreamIO.vector = Word8Vector.vector
where type StreamIO.elem = Word8.word
where type StreamIO.reader = BinPrimIO.reader
where type StreamIO.writer = BinPrimIO.writer
where type StreamIO.pos = BinPrimIO.pos
val openIn : string -> instream
val openOut : string -> outstream
val openAppend : string -> outstream
openIn name
openOut name
openOut
, the file is created if it does not already exist and truncated to length zero otherwise. These raise Io
if a stream cannot be opened on the given file or, in the case of openIn
, the file name does not exist.
openAppend name
Io
if a stream cannot be opened on the given file.
Beyond having the initial file position at the end of the file, any additional properties are system and implementation dependent. On operating systems (e.g., Unix) that support ``atomic append mode,'' each (flushed) output operation to the file will be appended to the end, even if there are other processes writing to the file simultaneously. Due to buffering, however, writing on an outstream
need not be atomic, i.e., output from a different process may interleave the output of a single write using the stream library. On certain other operating systems, having the file open for writing prevents any other process from opening the file for writing.
IMPERATIVE_IO
,OS.Path
,Posix.FileSys
,Posix.IO
,TextIO
All streams created by mkInstream
, mkOutstream
, and the open functions in BinIO
will be closed (and the output streams among them flushed) when the SML program exits.
Note that the BinIO.StreamIO.pos
type, equal to the BinPrimIO.pos
type, is concrete, being a synonym for Position.int
.
Generated April 12, 2004
Last Modified July 1, 2002
Comments to John Reppy.
This document may be distributed freely over the internet as long as the copyright notice and license terms below are prominently displayed within every machine-readable copy.
Copyright © 2004 AT&T and Lucent Technologies. All rights reserved.
Permission is granted for internet users to make one paper copy for their
own personal use. Further hardcopy reproduction is strictly prohibited.
Permission to distribute the HTML document electronically on any medium
other than the internet must be requested from the copyright holders by
contacting the editors.
Printed versions of the SML Basis Manual are available from Cambridge
University Press.
To order, please visit
www.cup.org (North America) or
www.cup.cam.ac.uk (outside North America). |