enumerator 0.3 → 0.3.0.1
raw patch · 3 files changed
+15/−7 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- enumerator.cabal +2/−2
- hs/Data/Enumerator/IO.hs +4/−1
- hs/Data/Enumerator/Text.hs +9/−4
enumerator.cabal view
@@ -1,5 +1,5 @@ name: enumerator-version: 0.3+version: 0.3.0.1 synopsis: Implementation of Oleg Kiselyov's left-fold enumerators license: MIT license-file: license.txt@@ -8,7 +8,7 @@ copyright: Copyright (c) John Millikin 2010 build-type: Simple cabal-version: >=1.6-category: Data+category: Data, Enumerator stability: experimental homepage: http://ianen.org/haskell/enumerator/ bug-reports: mailto:jmillikin@gmail.com
hs/Data/Enumerator/IO.hs view
@@ -20,6 +20,7 @@ import qualified Control.Exception as E import qualified Data.ByteString as B import qualified System.IO as IO+import System.IO.Error (isEOFError) -- | Read bytes (in chunks of the given buffer size) 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@@ -45,7 +46,9 @@ withBytes = tryStep $ do hasInput <- E.catch (IO.hWaitForInput h (-1))- (\(E.SomeException _) -> return False) + (\err -> if isEOFError err+ then return False+ else E.throwIO err) if hasInput then B.hGetNonBlocking h intSize else return B.empty
hs/Data/Enumerator/Text.hs view
@@ -31,6 +31,7 @@ import qualified Data.Text as T import qualified Data.Text.IO as T import qualified System.IO as IO+import System.IO.Error (isEOFError) import Control.Arrow (first) import Data.Bits ((.&.)) import qualified Data.ByteString as B@@ -53,12 +54,16 @@ -- 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- then return $ Continue k- else runIteratee (k (Chunks [text])) >>= loop+ loop (Continue k) = withText $ \maybeText -> case maybeText of+ Nothing -> return $ Continue k+ Just text -> runIteratee (k (Chunks [text])) >>= loop loop step = return step- withText = tryStep (T.hGetLine h)+ withText = tryStep $ E.catch+ (Just `fmap` T.hGetLine h)+ (\err -> if isEOFError err+ then return Nothing+ else E.throwIO err) -- | Opens a file path in text mode, and passes the handle to 'enumHandle'. -- The file will be closed when the 'Iteratee' finishes. enumFile :: FilePath -> Enumerator E.SomeException T.Text IO b