packages feed

cereal-conduit (empty) → 0.0.1

raw patch · 4 files changed

+96/−0 lines, 4 filesdep +basedep +bytestringdep +cerealsetup-changed

Dependencies added: base, bytestring, cereal, conduit, mtl

Files

+ Data/Conduit/Cereal.hs view
@@ -0,0 +1,40 @@+{-# LANGUAGE DeriveDataTypeable #-}+-- | Turn a 'Get' into a 'Sink' and a 'Put' into a 'Source'+module Data.Conduit.Cereal where++import qualified Data.ByteString as BS+import qualified Data.ByteString.Lazy as LBS+import Data.Typeable (Typeable)+import Control.Exception (Exception)+import Control.Monad.Trans+import qualified Data.Conduit as DC+import Data.Conduit.List (sourceList)+import Data.Serialize.Get+import Data.Serialize.Put++data GetError = GetError String+              | PrematureClose+  deriving (Show, Typeable)++instance Exception GetError++-- | 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'+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++-- | Convert a 'Put' into a 'Source'. Runs in constant memory.+sourcePut :: DC.Resource m => Put -> DC.Source m BS.ByteString+sourcePut put = sourceList $ LBS.toChunks $ runPutLazy put
+ LICENSE view
@@ -0,0 +1,25 @@+The following license covers this documentation, and the source code, except+where otherwise indicated.++Copyright 2010, Michael Snoyman. All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++* Redistributions of source code must retain the above copyright notice, this+  list of conditions and the following disclaimer.++* Redistributions in binary form must reproduce the above copyright notice,+  this list of conditions and the following disclaimer in the documentation+  and/or other materials provided with the distribution.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS "AS IS" AND ANY EXPRESS OR+IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO+EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,+OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF+LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE+OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF+ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ Setup.lhs view
@@ -0,0 +1,4 @@+#! /usr/bin/env runhaskell++> import Distribution.Simple+> main = defaultMain
+ cereal-conduit.cabal view
@@ -0,0 +1,27 @@+name:            cereal-conduit+version:         0.0.1+license:         BSD3+license-file:    LICENSE+author:          Myles C. Maxfield <myles.maxfield@gmail.com>+maintainer:      Myles C. Maxfield <myles.maxfield@gmail.com>+synopsis:        Turn Data.Serialize Gets and Puts into Sources and Sinks+description:     Turn Data.Serialize Gets and Puts into Sources and Sinks+category:        Conduit+stability:       Experimental+cabal-version:   >= 1.8+build-type:      Simple+homepage:        https://github.com/litherum/cereal-conduit++library+    build-depends: base     >= 4       && < 5+                 , conduit  >= 0.2.0+                 , cereal   >= 0.3.1.0+                 , mtl+                 , bytestring+    exposed-modules: Data.Conduit.Cereal+    ghc-options:     -Wall+++source-repository head+  type:     git+  location: git://github.com/litherum/cereal-conduit.git