packages feed

cereal-conduit 0.0.1 → 0.0.2

raw patch · 2 files changed

+20/−17 lines, 2 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

- Data.Conduit.Cereal: GetError :: String -> GetError
- Data.Conduit.Cereal: PrematureClose :: GetError
- Data.Conduit.Cereal: data GetError
- Data.Conduit.Cereal: instance Exception GetError
- Data.Conduit.Cereal: instance Show GetError
- Data.Conduit.Cereal: instance Typeable GetError
+ Data.Conduit.Cereal: GetDoesntConsumeInput :: GetException
+ Data.Conduit.Cereal: GetException :: String -> GetException
+ Data.Conduit.Cereal: data GetException
+ Data.Conduit.Cereal: instance Exception GetException
+ Data.Conduit.Cereal: instance Show GetException
+ Data.Conduit.Cereal: instance Typeable GetException

Files

Data/Conduit/Cereal.hs view
@@ -11,29 +11,32 @@ import Data.Conduit.List (sourceList) import Data.Serialize.Get import Data.Serialize.Put+import Control.Exception (throw) -data GetError = GetError String-              | PrematureClose+data GetException = GetException String+                  | GetDoesntConsumeInput   deriving (Show, Typeable) -instance Exception GetError+instance Exception GetException  -- | Convert a 'Get' into a 'Sink'. The 'Get' will be streamed bytes until it returns 'Done' or 'Fail'. ----- If the 'Get' fails, a GetError will be thrown with 'resourceThrow'+-- If the 'Get' fails, a GetException will be thrown with 'resourceThrow'. This function itself can also throw a GetException. sinkGet :: DC.ResourceThrow m => Get output -> DC.Sink BS.ByteString m output-sinkGet get = DC.SinkData { DC.sinkPush = push (runGetPartial get)-                          , DC.sinkClose = close-                          }-  where push f input = do-          case f input of-            Fail s -> lift $ DC.resourceThrow $ GetError s-            Partial f' -> return $ DC.Processing (push f') close-            Done r rest -> return $ DC.Done (if BS.null rest-                                               then Nothing-                                               else Just rest-                                            ) r-        close = lift $ DC.resourceThrow PrematureClose+sinkGet get = case runGetPartial get BS.empty of+                Fail s -> throw $ GetException s+                Partial f -> DC.SinkData { DC.sinkPush = push f+                                         , DC.sinkClose = close f+                                         }+                Done _ _ -> throw GetDoesntConsumeInput+  where push f input = case f input of+                         Fail s -> lift $ DC.resourceThrow $ GetException s+                         Partial f' -> return $ DC.Processing (push f') (close f')+                         Done r rest -> return $ DC.Done (if BS.null rest+                                                            then Nothing+                                                            else Just rest+                                                         ) r+        close f = let Fail s = f BS.empty in lift $ DC.resourceThrow $ GetException s  -- | Convert a 'Put' into a 'Source'. Runs in constant memory. sourcePut :: DC.Resource m => Put -> DC.Source m BS.ByteString
cereal-conduit.cabal view
@@ -1,5 +1,5 @@ name:            cereal-conduit-version:         0.0.1+version:         0.0.2 license:         BSD3 license-file:    LICENSE author:          Myles C. Maxfield <myles.maxfield@gmail.com>