@@ -7,29 +7,32 @@ import qualified Data.Text.Lazy.Encoding as T
7import qualified Data.ByteString.Lazy.Char8 as B
7import qualified Data.ByteString.Lazy.Char8 as B
8import qualified Data.ByteString.Char8 as BS
8import qualified Data.ByteString.Char8 as BS
9import qualified Data.ByteString.Lazy.Search as B
9import qualified Data.ByteString.Lazy.Search as B
11−string :: FilePath -> IO ()
12+string :: Handle -> IO ()
12−string file = readFile file >>= print . length
13+string h = hGetContents h >>= print . length
14−text :: FilePath -> IO ()
15+text :: Handle -> IO ()
15−text file = do
16+text h = do
16− t <- {-# SCC "T.readFile" #-} T.readFile file
17+ t <- {-# SCC "T.hGetContents" #-} T.hGetContents h
17 print (T.length t)
18 print (T.length t)
19−textBS :: FilePath -> IO ()
20+textBS :: Handle -> IO ()
20−textBS file = do
21+textBS h = do
21− bs <- {-# SCC "B.readFile" #-} B.readFile file
22+ bs <- {-# SCC "B.hGetContents" #-} B.hGetContents h
22 print . T.length . T.decodeUtf8 $ bs
23 print . T.length . T.decodeUtf8 $ bs
24−bytestring :: FilePath -> IO ()
25+bytestring :: Handle -> IO ()
25−bytestring file = do
26+bytestring h = do
26− bs <- {-# SCC "B.readFile" #-}B.readFile file
27+ bs <- {-# SCC "B.hGetContents" #-} B.hGetContents h
27 print (B.length bs)
28 print (B.length bs)
30 (name : file : _) <- getArgs
31 (name : file : _) <- getArgs
32+ h <- openFile file ReadMode
33+ hSetBuffering h (BlockBuffering (Just 16384))
31 case name of
34 case name of
32− "bs" -> bytestring file
35+ "bs" -> bytestring h
33− "string" -> string file
36+ "string" -> string h
34− "text" -> text file
37+ "text" -> text h
35− "textBS" -> textBS file
38+ "textBS" -> textBS h