0 | module Libraries.Utils.Binary
21 | newBinary : Buffer -> Integer -> Binary
22 | newBinary b s = MkBin b 0 s 0
29 | avail : Binary -> Integer
30 | avail c = (size c - loc c) - 1
33 | toRead : Binary -> Integer
34 | toRead c = used c - loc c
37 | appended : Integer -> Binary -> Binary
38 | appended i (MkBin b loc s used) = MkBin b (loc+i) s (used + i)
41 | incLoc : Integer -> Binary -> Binary
42 | incLoc i c = { loc $= (+i) } c
45 | dumpBin : Binary -> IO ()
48 | printLn !(bufferData' (buf chunk))
52 | fromBuffer : Buffer -> IO Binary
54 | = do len <- rawSize buf
56 | pure (MkBin buf 0 len len)
59 | writeToFile : (fname : String) -> Binary -> IO (Either FileError ())
61 | = do Right ok <- writeBufferToFile fname (buf c) (cast $
used c)
62 | | Left (err, size) => pure (Left err)
66 | readFromFile : (fname : String) -> IO (Either FileError Binary)
68 | = do Right b <- createBufferFromFile fname
69 | | Left err => pure (Left err)
71 | let bsize = cast bsize
72 | pure (Right (MkBin b 0 bsize bsize))