[Pkg-haskell-commits] [SCM] haskell-testpack branch, master, updated. debian/1.0.2-1-4-gb0d6b36

John Goerzen jgoerzen at complete.org
Fri Apr 23 14:42:33 UTC 2010


The following commit has been merged in the master branch:
commit 5d385a6c5883c8fdee69a68a2245e3ff116997e4
Author: John Goerzen <jgoerzen at complete.org>
Date:   Tue Oct 5 22:30:51 2004 +0100

    More IO utils
    
    Keywords:
    
    
    (jgoerzen at complete.org--projects/missingh--head--1.0--patch-17)

diff --git a/MissingH/IOutil.hs b/MissingH/IOutil.hs
index eda0530..03ef72f 100644
--- a/MissingH/IOutil.hs
+++ b/MissingH/IOutil.hs
@@ -26,7 +26,8 @@ module MissingH.IOutil(-- * Line Processing Utilities
                        -- * Lazy Interaction
                        hInteract, lineInteract, hLineInteract,
                        -- * Binary Files
-                       hPutBufStr, hGetBufStr, hFullGetBufStr
+                       hPutBufStr, hGetBufStr, hFullGetBufStr,
+                       hGetBlocks, hFullGetBlocks
                         ) where
 
 import Foreign.Ptr
@@ -158,3 +159,24 @@ hFullGetBufStr f count = do
                                  remainder <- hFullGetBufStr f (count - (length thisstr))
                                  return (thisstr ++ remainder)
 
+{- | Returns a lazily-evaluated list of all blocks in the input file,
+as read by 'hGetBufStr'.  There will be no 0-length block in this list.
+The list simply ends at EOF. -}
+hGetBlocks :: Handle -> Int -> IO [String]
+hGetBlocks = hGetBlocksUtil hGetBufStr
+
+{- | Same as 'hGetBlocks', but using 'hFullGetBufStr' underneath. -}
+hFullGetBlocks :: Handle -> Int -> IO [String]
+hFullGetBlocks = hGetBlocksUtil hFullGetBufStr
+
+
+hGetBlocksUtil :: (Handle -> Int -> IO String) -> Handle -> Int -> IO [String]
+hGetBlocksUtil readfunc h count =
+    unsafeInterleaveIO (do
+                       block <- readfunc h count
+                       if block == ""
+                          then return []
+                          else do
+                               remainder <- hGetBlocksUtil readfunc h count
+                               return (block : remainder)
+                       )
\ No newline at end of file

-- 
haskell-testpack



More information about the Pkg-haskell-commits mailing list