streaming-cassava 0.1.0.1 → 0.1.0.2
raw patch · 4 files changed
+49/−34 lines, 4 filesdep ~hspecPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependency ranges changed: hspec
API changes (from Hackage documentation)
- Streaming.Cassava: instance GHC.Exception.Exception Streaming.Cassava.CsvParseException
+ Streaming.Cassava: instance GHC.Exception.Type.Exception Streaming.Cassava.CsvParseException
- Streaming.Cassava: data DecodeOptions :: *
+ Streaming.Cassava: data DecodeOptions
- Streaming.Cassava: data EncodeOptions :: *
+ Streaming.Cassava: data EncodeOptions
- Streaming.Cassava: data HasHeader :: *
+ Streaming.Cassava: data HasHeader
Files
- ChangeLog.md +4/−0
- README.md +4/−6
- src/Streaming/Cassava.hs +36/−25
- streaming-cassava.cabal +5/−3
ChangeLog.md view
@@ -1,5 +1,9 @@ # Revision history for streaming-cassava +## 0.1.0.2 -- 2021-02-28++* Fix issues with `readFile`.+ ## 0.1.0.1 -- 2018-01-23 * Bump dependency on `streaming`.
README.md view
@@ -1,7 +1,7 @@ streaming-cassava ================= -[](https://hackage.haskell.org/package/streaming-cassava) [](https://travis-ci.org/haskell-streaming/streaming-cassava)+[](https://hackage.haskell.org/package/streaming-cassava) [](https://github.com/haskell-streaming/streaming-cassava/actions/workflows/haskell-ci.yml) > [cassava] support for the [streaming] ecosystem @@ -18,15 +18,13 @@ to fail on the first parse error or handle errors on a row-by-row basis. -Errors with `readFile`+Reading data from file ---------------------- A common use-case is to stream CSV-encoded data in from a file. You may be tempted to use `readFile` from [streaming-bytestring] to obtain-the file contents, but if you do you're likely to run into exceptions-such as `hGetBufSome: illegal operation (handle is closed)`.--The recommended solution is to use the [streaming-with] package for+the file contents, and for simple cases this should suffice. However,+the recommended solution is to use the [streaming-with] package for the IO aspects. You can then write something like: ```haskell
src/Streaming/Cassava.hs view
@@ -1,5 +1,7 @@-{-# LANGUAGE FlexibleContexts, MultiParamTypeClasses, OverloadedStrings,- ScopedTypeVariables #-}+{-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE MultiParamTypeClasses #-}+{-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE ScopedTypeVariables #-} {- | Module : Streaming.Cassava@@ -71,24 +73,27 @@ import Streaming (Of, Stream) import qualified Streaming.Prelude as S -import Data.Csv (DecodeOptions(..), DefaultOrdered(..),- EncodeOptions(..), FromNamedRecord(..),- FromRecord(..), Header, Name,- ToNamedRecord(..), ToRecord(..),- defaultDecodeOptions,- defaultEncodeOptions, encIncludeHeader,- header)-import Data.Csv.Incremental (HasHeader(..), HeaderParser(..),- Parser(..))-import qualified Data.Csv.Incremental as CI+import Data.Csv (DecodeOptions (..),+ DefaultOrdered (..),+ EncodeOptions (..),+ FromNamedRecord (..),+ FromRecord (..), Header,+ Name, ToNamedRecord (..),+ ToRecord (..),+ defaultDecodeOptions,+ defaultEncodeOptions,+ encIncludeHeader, header)+import Data.Csv.Incremental (HasHeader (..),+ HeaderParser (..),+ Parser (..))+import qualified Data.Csv.Incremental as CI -import Control.Exception (Exception(..))-import Control.Monad.Error.Class (MonadError, throwError)-import Control.Monad.Trans.Class (lift)-import Data.Bifunctor (first)-import Data.Maybe (fromMaybe)-import Data.String (IsString(..))-import Data.Typeable (Typeable)+import Control.Exception (Exception (..))+import Control.Monad.Error.Class (MonadError, throwError)+import Control.Monad.Trans.Class (lift)+import Data.Bifunctor (first)+import Data.String (IsString (..))+import Data.Typeable (Typeable) -------------------------------------------------------------------------------- @@ -126,9 +131,12 @@ -> Stream (Of (Either CsvParseException a)) m (Either (CsvParseException, ByteString m r) r) runParser = loop where- feed f str = (uncurry (loop . f) . fromMaybe (mempty, str))- -- nxt == Nothing, str is just Return- =<< lift (B.unconsChunk str)+ feed f str = do+ nxt <- lift (B.nextChunk str)+ let g = loop . f+ case nxt of+ Left r -> pure $ Right r+ Right (chunk, rest) -> g chunk rest loop p str = case p of Fail bs err -> return (Left (CsvParseException err, B.consChunk bs str))@@ -187,9 +195,12 @@ PartialH get -> feedH get str DoneH _ p -> runParser p str - feedH f str = (uncurry (loopH . f) . fromMaybe (mempty, str))- -- nxt == Nothing, str is just Return- =<< lift (B.unconsChunk str)+ feedH f str = do+ nxt <- lift (B.nextChunk str)+ let g = loopH . f+ case nxt of+ Left r -> pure $ Right r+ Right (chunk, rest) -> g chunk rest --------------------------------------------------------------------------------
streaming-cassava.cabal view
@@ -1,5 +1,5 @@ name: streaming-cassava-version: 0.1.0.1+version: 0.1.0.2 synopsis: Cassava support for the streaming ecosystem description:@@ -16,8 +16,10 @@ build-type: Simple extra-source-files: ChangeLog.md, README.md cabal-version: >=1.10-tested-with: GHC == 8.0.2, GHC == 8.1.* +tested-with: GHC == 8.0.2, GHC == 8.2.2, GHC == 8.4.4, GHC == 8.6.5,+ GHC == 8.8.4, GHC == 8.10.4+ source-repository head type: git location: https://github.com/haskell-streaming/streaming-cassava.git@@ -41,7 +43,7 @@ main-is: roundtrip.hs build-depends: streaming-cassava , base- , hspec == 2.4.*+ , hspec >= 2.4 && < 2.8 , mtl >= 2.2.1 && < 2.3 , QuickCheck == 2.* , quickcheck-instances