enumerator 0.2.1 → 0.3
raw patch · 3 files changed
+13/−19 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
- Data.Enumerator.IO: iterFile :: FilePath -> Iteratee SomeException ByteString IO ()
- Data.Enumerator.Text: iterFile :: FilePath -> Iteratee SomeException Text IO ()
Files
- enumerator.cabal +1/−1
- hs/Data/Enumerator/IO.hs +6/−9
- hs/Data/Enumerator/Text.hs +6/−9
enumerator.cabal view
@@ -1,5 +1,5 @@ name: enumerator-version: 0.2.1+version: 0.3 synopsis: Implementation of Oleg Kiselyov's left-fold enumerators license: MIT license-file: license.txt
hs/Data/Enumerator/IO.hs view
@@ -13,7 +13,6 @@ module Data.Enumerator.IO ( enumHandle , enumFile- , iterFile , iterHandle ) where import Data.Enumerator@@ -29,6 +28,9 @@ -- This enumerator blocks until at least one byte is available from the -- handle, and might read less than the maximum buffer size in some -- cases.+--+-- The handle should be opened with no encoding, and in 'IO.ReadMode' or+-- 'IO.ReadWriteMode'. enumHandle :: Integer -- ^ Buffer size -> IO.Handle -> Enumerator E.SomeException B.ByteString IO b@@ -58,6 +60,9 @@ -- | Read bytes from a stream and write them to a handle. If an exception -- occurs during file IO, enumeration will stop and 'Error' will be -- returned.+--+-- The handle should be opened with no encoding, and in 'IO.WriteMode' or+-- 'IO.ReadWriteMode'. iterHandle :: IO.Handle -> Iteratee E.SomeException B.ByteString IO () iterHandle h = continue step where step EOF = yield () EOF@@ -65,11 +70,3 @@ step (Chunks bytes) = Iteratee io where put = mapM_ (B.hPut h) bytes io = tryStep put (\_ -> return $ Continue step)--- | Opens a file path in binary mode, and passes the handle to 'iterHandle'.--- The file will be closed when the 'Iteratee' finishes.-iterFile :: FilePath -> Iteratee E.SomeException B.ByteString IO ()-iterFile path = Iteratee io where- withHandle = tryStep (IO.openBinaryFile path IO.WriteMode)- io = withHandle $ \h -> E.finally- (runIteratee (iterHandle h))- (IO.hClose h)
hs/Data/Enumerator/Text.hs view
@@ -15,7 +15,6 @@ enumHandle , enumFile , iterHandle- , iterFile -- * Codecs , Codec , encode@@ -49,6 +48,9 @@ -- | Read lines of text from the handle, and stream them to an 'Iteratee'. -- If an exception occurs during file IO, enumeration will stop and 'Error' -- will be returned. Exceptions from the iteratee are not caught.+--+-- The handle should be opened with an appropriate text encoding, and+-- in 'IO.ReadMode' or 'IO.ReadWriteMode'. enumHandle :: IO.Handle -> Enumerator E.SomeException T.Text IO b enumHandle h = Iteratee . loop where loop (Continue k) = withText $ \text -> if T.null text@@ -68,6 +70,9 @@ -- | Read text from a stream and write it to a handle. If an exception -- occurs during file IO, enumeration will stop and 'Error' will be -- returned.+--+-- The handle should be opened with an appropriate text encoding, and+-- in 'IO.WriteMode' or 'IO.ReadWriteMode'. iterHandle :: IO.Handle -> Iteratee E.SomeException T.Text IO () iterHandle h = continue step where step EOF = yield () EOF@@ -75,14 +80,6 @@ step (Chunks chunks) = Iteratee io where put = mapM_ (T.hPutStr h) chunks io = tryStep put (\_ -> return $ Continue step)--- | Opens a file path in text mode, and passes the handle to 'iterHandle'.--- The file will be closed when the 'Iteratee' finishes.-iterFile :: FilePath -> Iteratee E.SomeException T.Text IO ()-iterFile path = Iteratee io where- withHandle = tryStep (IO.openFile path IO.WriteMode)- io = withHandle $ \h -> E.finally- (runIteratee (iterHandle h))- (IO.hClose h) data Codec = Codec { codecName :: T.Text , codecEncode :: [T.Text] -> Either E.SomeException [B.ByteString]