1signature OUT  =
2sig
3  type byte
4  val startOut  :  string -> unit
5  val endOut    :  unit   -> unit
6  val outByte   :  byte   -> unit
7  val outPos    :  unit   -> int
8  exception NoOut
9end
10(*----------*)
11
12structure Out: OUT  =
13struct
14  open BinIO
15  type byte = Word8.word
16  exception NoOut
17
18  val out = ref (NONE: outstream option)
19
20  fun startOut fileName   =
21    ( case  !out  of  NONE    =>  ()
22                   |  SOME s  =>  closeOut s;
23      out := SOME (openOut fileName) )
24
25  fun getStream ()  =
26      case  !out  of  NONE    =>  raise NoOut
27                   |  SOME s  =>  s
28
29  fun outByte b  =  output1   (getStream (), b)
30
31  fun outPos ()  =  StreamIO.filePosOut (getPosOut (getStream ()))
32
33  fun endOut ()  =  closeOut  (getStream ())
34
35end
36