2019-06-25 23:27:46 +03:00
|
|
|
import Data.Buffer
|
|
|
|
import System.File
|
|
|
|
|
|
|
|
main : IO ()
|
|
|
|
main
|
2020-01-31 19:40:18 +03:00
|
|
|
= do Just buf <- newBuffer 100
|
|
|
|
| Nothing => putStrLn "Buffer creation failed"
|
2019-06-25 23:27:46 +03:00
|
|
|
s <- rawSize buf
|
|
|
|
printLn s
|
|
|
|
|
|
|
|
setInt buf 1 94
|
|
|
|
val <- getInt buf 1
|
|
|
|
printLn val
|
|
|
|
|
|
|
|
setDouble buf 10 94.42
|
|
|
|
val <- getDouble buf 10
|
|
|
|
printLn val
|
|
|
|
|
|
|
|
setString buf 20 "Hello there!"
|
|
|
|
val <- getString buf 20 5
|
|
|
|
printLn val
|
|
|
|
|
|
|
|
val <- getString buf 26 6
|
|
|
|
printLn val
|
|
|
|
|
|
|
|
ds <- bufferData buf
|
|
|
|
printLn ds
|
|
|
|
|
|
|
|
Right f <- openBinaryFile "test.buf" WriteTruncate
|
|
|
|
| Left err => putStrLn "File error on write"
|
2019-09-28 20:33:46 +03:00
|
|
|
Right _ <- writeBufferToFile f buf 100
|
|
|
|
| Left err => do putStrLn "Buffer write fail"
|
|
|
|
closeFile f
|
2019-06-25 23:27:46 +03:00
|
|
|
closeFile f
|
|
|
|
|
|
|
|
Right f <- openBinaryFile "test.buf" Read
|
|
|
|
| Left err => putStrLn "File error on read"
|
2020-01-31 19:40:18 +03:00
|
|
|
Right buf2 <- createBufferFromFile f
|
2019-09-28 20:33:46 +03:00
|
|
|
| Left err => do putStrLn "Buffer read fail"
|
|
|
|
closeFile f
|
|
|
|
closeFile f
|
2019-06-25 23:27:46 +03:00
|
|
|
|
|
|
|
ds <- bufferData buf2
|
|
|
|
printLn ds
|
2019-09-28 20:33:46 +03:00
|
|
|
|
|
|
|
Right f <- openBinaryFile "test.buf" Read
|
|
|
|
| Left err => putStrLn "File error on read"
|
2020-01-31 19:40:18 +03:00
|
|
|
Just buf3 <- newBuffer 99
|
|
|
|
| Nothing => putStrLn "Buffer creation failed"
|
2019-09-28 20:33:46 +03:00
|
|
|
Right _ <- readBufferFromFile f buf3 100
|
|
|
|
| Left err => do putStrLn "Buffer read fail"
|
|
|
|
closeFile f
|
|
|
|
closeFile f
|
|
|
|
|