blob: 6c1ad2f57a94b722751b60fd4c017bb6ab31e31d (
plain)
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
|
-- !!! Testing IO.hFileSize
module Main(main) where
import Control.Monad
import System.Directory ( removeFile, doesFileExist )
import System.IO
main = do
sz <- hFileSize stdin `catch` (\ _ -> return (-1))
print sz
let fn = "hFileSize002.out"
f <- doesFileExist fn
when f (removeFile fn)
hdl <- openFile fn WriteMode
hPutStr hdl "file_size"
-- with default buffering
sz <- hFileSize hdl
print sz
hSetBuffering hdl NoBuffering
hPutStr hdl "file_size"
-- with no buffering
sz <- hFileSize hdl
print sz
hSetBuffering hdl LineBuffering
hPutStr hdl "file_size"
-- with line buffering
sz <- hFileSize hdl
print sz
hSetBuffering hdl (BlockBuffering (Just 4))
-- with block buffering
hPutStr hdl "file_size"
sz <- hFileSize hdl
print sz
hClose hdl
|