-
Notifications
You must be signed in to change notification settings - Fork 0
/
binrandomaccessfile.sml
37 lines (31 loc) · 1.17 KB
/
binrandomaccessfile.sml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
structure BinRandomAccessFile :> sig
type infile
val openIn : string -> infile
val read : infile * int -> Word8Vector.vector
val tellIn : infile -> Position.int
val seekIn : infile * Position.int -> unit
val endPosIn : infile -> Position.int
val closeIn : infile -> unit
end = struct
type infile = BinIO.StreamIO.reader
fun openIn fileName =
let
val ins = BinIO.getInstream (BinIO.openIn fileName)
val (reader, buffer) = BinIO.StreamIO.getReader ins
in
reader
end
fun read (BinPrimIO.RD {readVec = SOME readVec, ...}, n) =
readVec n
| read _ = raise Fail "BinRandomAccessFile.read not supported"
fun tellIn (BinPrimIO.RD {getPos = SOME getPos, ...}) =
getPos ()
| tellIn _ = raise Fail "BinRandomAccessFile.tellIn not supported"
fun seekIn (BinPrimIO.RD {setPos = SOME setPos, ...}, pos) =
setPos pos
| seekIn _ = raise Fail "BinRandomAccessFile.seekIn not supported"
fun endPosIn (BinPrimIO.RD {endPos = SOME endPos, ...}) =
endPos ()
| endPosIn _ = raise Fail "BinRandomAccessFile.lengthIn not supported"
fun closeIn (BinPrimIO.RD {close, ...}) = close ()
end