packages feed

streaming-commons 0.1.19 → 0.2.0.0

raw patch · 8 files changed

+29/−268 lines, 8 filesdep −blaze-builderPVP ok

version bump matches the API change (PVP)

Dependencies removed: blaze-builder

API changes (from Hackage documentation)

- Data.Streaming.Blaze: allNewBuffersStrategy :: Int -> BufferAllocStrategy
- Data.Streaming.Blaze: allocBuffer :: Int -> IO Buffer
- Data.Streaming.Blaze: bufferSize :: Buffer -> Int
- Data.Streaming.Blaze: data Buffer
- Data.Streaming.Blaze: defaultStrategy :: BufferAllocStrategy
- Data.Streaming.Blaze: freeSize :: Buffer -> Int
- Data.Streaming.Blaze: newBlazeRecv :: BufferAllocStrategy -> IO (BlazeRecv, BlazeFinish)
- Data.Streaming.Blaze: nextSlice :: Int -> Buffer -> Maybe Buffer
- Data.Streaming.Blaze: reuseBuffer :: Buffer -> Buffer
- Data.Streaming.Blaze: reuseBufferStrategy :: IO Buffer -> BufferAllocStrategy
- Data.Streaming.Blaze: sliceSize :: Buffer -> Int
- Data.Streaming.Blaze: type BlazeFinish = IO (Maybe ByteString)
- Data.Streaming.Blaze: type BlazePopper = IO ByteString
- Data.Streaming.Blaze: type BlazeRecv = Builder -> IO BlazePopper
- Data.Streaming.Blaze: type BufferAllocStrategy = (IO Buffer, Int -> Buffer -> IO (IO Buffer))
- Data.Streaming.Blaze: unsafeFreezeBuffer :: Buffer -> ByteString
- Data.Streaming.Blaze: unsafeFreezeNonEmptyBuffer :: Buffer -> Maybe ByteString
- Data.Streaming.ByteString.Builder.Class: builderFlush :: StreamingBuilder b => b
- Data.Streaming.ByteString.Builder.Class: class Monoid b => StreamingBuilder b
- Data.Streaming.ByteString.Builder.Class: instance Data.Streaming.ByteString.Builder.Class.StreamingBuilder Data.ByteString.Builder.Internal.Builder
- Data.Streaming.ByteString.Builder.Class: newBuilderRecv :: StreamingBuilder b => BufferAllocStrategy -> IO (b -> IO BuilderPopper, BuilderFinish)
+ Data.Streaming.ByteString.Builder: newBuilderRecv :: BufferAllocStrategy -> IO (BuilderRecv, BuilderFinish)

Files

ChangeLog.md view
@@ -1,3 +1,7 @@+## 0.2.0++* Drop `blaze-builder` dependency+ ## 0.1.19  * Update `getAddrInfo` hints to allow hostnames and portnames [#46](https://github.com/fpco/streaming-commons/issues/46)
− Data/Streaming/Blaze.hs
@@ -1,150 +0,0 @@-{-# LANGUAGE CPP #-}-{-# LANGUAGE FlexibleContexts #-}-{-# LANGUAGE BangPatterns #-}-{-# LANGUAGE RankNTypes #-}--- | Convert a stream of blaze-builder @Builder@s into a stream of @ByteString@s.------ Adapted from blaze-builder-enumerator, written by myself and Simon Meier.------ Note: if you have blaze-builder >= 0.4, 'newBlazeRecv' just calls--- 'Data.Streaming.ByteString.Builder.newByteStringBuilderRecv'---- Note that the functions here can work in any monad built on top of @IO@ or--- @ST@.-module Data.Streaming.Blaze-    ( BlazeRecv-    , BlazePopper-    , BlazeFinish-    , newBlazeRecv--  -- * Buffers-  , Buffer--  -- ** Status information-  , freeSize-  , sliceSize-  , bufferSize--  -- ** Creation and modification-  , allocBuffer-  , reuseBuffer-  , nextSlice--  -- ** Conversion to bytestings-  , unsafeFreezeBuffer-  , unsafeFreezeNonEmptyBuffer--  -- * Buffer allocation strategies-  , BufferAllocStrategy-  , allNewBuffersStrategy-  , reuseBufferStrategy-  , defaultStrategy-    ) where--import Blaze.ByteString.Builder-import qualified Data.ByteString as S--#if MIN_VERSION_blaze_builder(0,4,0)--import Data.Streaming.ByteString.Builder--newBlazeRecv :: BufferAllocStrategy -> IO (BlazeRecv, BlazeFinish)-newBlazeRecv = newByteStringBuilderRecv-{-# INLINE newBlazeRecv #-}--#else /* !MIN_VERSION_blaze_builder(0,4,0) */--import Blaze.ByteString.Builder.Internal hiding (insertByteString)-import Blaze.ByteString.Builder.Internal.Types hiding (insertByteString)-import Blaze.ByteString.Builder.Internal.Buffer (execBuildStep)-import Data.IORef--import Data.Streaming.ByteString.Builder.Buffer--newBlazeRecv :: BufferAllocStrategy -> IO (BlazeRecv, BlazeFinish)-newBlazeRecv (ioBufInit, nextBuf) = do-    refBuf <- newIORef ioBufInit-    return (push refBuf, finish refBuf)-  where-    finish refBuf = do-        ioBuf <- readIORef refBuf-        buf <- ioBuf-        return $ unsafeFreezeNonEmptyBuffer buf--    push refBuf builder = do-        refStep <- newIORef $ Left $ unBuilder builder (buildStep finalStep)-        return $ popper refBuf refStep-      where-        finalStep !(BufRange pf _) = return $ Done pf ()--    popper refBuf refStep = do-        ioBuf <- readIORef refBuf-        ebStep <- readIORef refStep-        case ebStep of-            Left bStep -> do-                !buf   <- ioBuf-                signal <- execBuildStep bStep buf-                case signal of-                    Done op' _ -> do-                        writeIORef refBuf $ return $ updateEndOfSlice buf op'-                        return S.empty-                    BufferFull minSize op' bStep' -> do-                        let buf' = updateEndOfSlice buf op'-                            {-# INLINE cont #-}-                            cont mbs = do-                                -- sequencing the computation of the next buffer-                                -- construction here ensures that the reference to the-                                -- foreign pointer `fp` is lost as soon as possible.-                                ioBuf' <- nextBuf minSize buf'-                                writeIORef refBuf ioBuf'-                                writeIORef refStep $ Left bStep'-                                case mbs of-                                    Just bs | not $ S.null bs -> return bs-                                    _ -> popper refBuf refStep-                        cont $ unsafeFreezeNonEmptyBuffer buf'-                    InsertByteString op' bs bStep' -> do-                        let buf' = updateEndOfSlice buf op'-                        let yieldBS = do-                                nextBuf 1 buf' >>= writeIORef refBuf-                                writeIORef refStep $ Left bStep'-                                if S.null bs-                                    then popper refBuf refStep-                                    else return bs-                        case unsafeFreezeNonEmptyBuffer buf' of-                            Nothing -> yieldBS-                            Just bs' -> do-                                writeIORef refStep $ Right yieldBS-                                return bs'-            Right action -> action--{--helper :: (MonadBase base m, PrimMonad base, Monad (t m), MonadTrans t)-       => t m (Maybe (Flush Builder))-       -> (Flush S.ByteString -> t m ())-       -> BufferAllocStrategy-       -> t m ()-helper await' yield' (ioBufInit, nextBuf) =-    loop ioBufInit-  where-    loop ioBuf = do-        await' >>= maybe (close ioBuf) (cont' ioBuf)--    cont' ioBuf Flush = push ioBuf flush $ \ioBuf' -> yield' Flush >> loop ioBuf'-    cont' ioBuf (Chunk builder) = push ioBuf builder loop--    close ioBuf = do-        buf <- lift $ unsafeLiftIO $ ioBuf-        maybe (return ()) (yield' . Chunk) (unsafeFreezeNonEmptyBuffer buf)--}--#endif /* !MIN_VERSION_blaze_builder(0,4,0) */---- | Provides a series of @ByteString@s until empty, at which point it provides--- an empty @ByteString@.------ Since 0.1.2-type BlazePopper = IO S.ByteString--type BlazeRecv = Builder -> IO BlazePopper--type BlazeFinish = IO (Maybe S.ByteString)
Data/Streaming/ByteString/Builder.hs view
@@ -19,6 +19,7 @@     ( BuilderRecv     , BuilderPopper     , BuilderFinish+    , newBuilderRecv     , newByteStringBuilderRecv      -- * toByteStringIO@@ -74,6 +75,10 @@ type BuilderRecv = Builder -> IO BuilderPopper  type BuilderFinish = IO (Maybe S.ByteString)++newBuilderRecv :: BufferAllocStrategy -> IO (BuilderRecv, BuilderFinish)+newBuilderRecv = newByteStringBuilderRecv+{-# INLINE newBuilderRecv #-}  newByteStringBuilderRecv :: BufferAllocStrategy -> IO (BuilderRecv, BuilderFinish) newByteStringBuilderRecv (ioBufInit, nextBuf) = do
Data/Streaming/ByteString/Builder/Buffer.hs view
@@ -40,8 +40,6 @@  import Data.ByteString.Lazy.Internal (defaultChunkSize) -#if MIN_VERSION_blaze_builder(0,4,0)- import qualified Data.ByteString as S import qualified Data.ByteString.Internal as S import Foreign (Word8, ForeignPtr, Ptr, plusPtr, minusPtr)@@ -196,13 +194,6 @@     tryReuseBuffer reqSize buf       | bufferSize buf >= reqSize = return $ return (reuseBuffer buf)       | otherwise                 = return $ allocBuffer reqSize---#else  /* !MIN_VERSION_blaze_builder(0,4,0) */--import Blaze.ByteString.Builder.Internal.Buffer--#endif /* !MIN_VERSION_blaze_builder(0,4,0) */  defaultStrategy :: BufferAllocStrategy defaultStrategy = allNewBuffersStrategy defaultChunkSize
− Data/Streaming/ByteString/Builder/Class.hs
@@ -1,43 +0,0 @@-{-# LANGUAGE CPP #-}--- | Typeclass to stream blaze-builder and bytestring(-builder) @Builder@s.------ Since 0.1.10.0----module Data.Streaming.ByteString.Builder.Class-    ( StreamingBuilder (..)-    , module Data.Streaming.ByteString.Builder-    ) where--import qualified Data.ByteString.Builder-import qualified Data.ByteString.Builder.Internal-import Data.Monoid (Monoid)--import Data.Streaming.ByteString.Builder hiding (newByteStringBuilderRecv)-import qualified Data.Streaming.ByteString.Builder--#if !MIN_VERSION_blaze_builder(0,4,0)--import qualified Blaze.ByteString.Builder--import Data.Streaming.Blaze--instance StreamingBuilder Blaze.ByteString.Builder.Builder where-    newBuilderRecv = newBlazeRecv-    builderFlush   = Blaze.ByteString.Builder.flush--#endif /* !MIN_VERSION_blaze_builder(0,4,0) */---- | Typeclass to stream blaze-builder (< 0.4) and bytestring(-builder) @Builder@s.--- This is primarily to aid the transition from blaze-builder to bytestring @Builder@s--- (if using blaze-builder >= 0.4, there is only one instance, since the @Builder@--- type is shared).------ Since 0.1.10.0----class Data.Monoid.Monoid b => StreamingBuilder b where-    newBuilderRecv :: BufferAllocStrategy -> IO (b -> IO BuilderPopper, BuilderFinish)-    builderFlush   :: b--instance StreamingBuilder Data.ByteString.Builder.Builder where-    newBuilderRecv = Data.Streaming.ByteString.Builder.newByteStringBuilderRecv-    builderFlush   = Data.ByteString.Builder.Internal.flush
streaming-commons.cabal view
@@ -1,5 +1,5 @@ name:                streaming-commons-version:             0.1.19+version:             0.2.0.0 synopsis:            Common lower-level functions needed by various streaming data libraries description:         Provides low-dependency functionality commonly needed by various streaming data libraries, such as conduit and pipes. homepage:            https://github.com/fpco/streaming-commons@@ -25,10 +25,8 @@   default: False  library-  exposed-modules:     Data.Streaming.Blaze-                       Data.Streaming.ByteString.Builder+  exposed-modules:     Data.Streaming.ByteString.Builder                        Data.Streaming.ByteString.Builder.Buffer-                       Data.Streaming.ByteString.Builder.Class                        Data.Streaming.FileRead                        Data.Streaming.Filesystem                        Data.Streaming.Network@@ -50,7 +48,6 @@   build-depends:       base >= 4.7 && < 5                      , array                      , async-                     , blaze-builder >= 0.3 && < 0.5                      , bytestring                      , directory                      , network >= 2.4.0.0@@ -85,7 +82,6 @@     type:           exitcode-stdio-1.0     ghc-options:    -Wall -threaded     other-modules:  Data.Streaming.ByteString.BuilderSpec-                    Data.Streaming.BlazeSpec                     Data.Streaming.FileReadSpec                     Data.Streaming.FilesystemSpec                     Data.Streaming.NetworkSpec@@ -99,7 +95,6 @@                   , QuickCheck                   , array                   , async-                  , blaze-builder                   , bytestring                   , deepseq                   , network >= 2.4.0.0@@ -144,7 +139,6 @@     main-is:        builder-to-bytestring-io.hs     ghc-options:    -Wall -O2     build-depends:  base-                  , blaze-builder                   , bytestring >= 0.10.2                   , gauge                   , deepseq
− test/Data/Streaming/BlazeSpec.hs
@@ -1,16 +0,0 @@-{-# LANGUAGE OverloadedStrings #-}-module Data.Streaming.BlazeSpec (spec) where--import Test.Hspec-import qualified Blaze.ByteString.Builder as B-import Data.Streaming.ByteString.BuilderSpec hiding (spec)--spec :: Spec-spec = do-    describe "Data.Streaming.Blaze" $ builderSpec BuilderFunctions-        { bfFromByteString       = B.fromByteString-        , bfInsertLazyByteString = B.insertLazyByteString-        , bfToLazyByteString     = B.toLazyByteString-        , bfInsertByteString     = B.insertByteString-        , bfCopyByteString       = B.copyByteString-        }
test/Data/Streaming/ByteString/BuilderSpec.hs view
@@ -3,14 +3,13 @@ {-# LANGUAGE ScopedTypeVariables #-} module Data.Streaming.ByteString.BuilderSpec     ( spec-    , builderSpec-    , BuilderFunctions(..)     ) where  import qualified Data.ByteString as S import Data.ByteString.Char8 () import qualified Data.ByteString.Unsafe as S import qualified Data.ByteString.Builder as B+import Data.ByteString.Builder (Builder) import qualified Data.ByteString.Builder.Internal as B import qualified Data.ByteString.Lazy as L import Data.ByteString.Lazy.Char8 ()@@ -21,17 +20,8 @@ import Test.Hspec.QuickCheck (prop)  import Data.Streaming.ByteString.Builder-import Data.Streaming.ByteString.Builder.Class -data BuilderFunctions b = BuilderFunctions-    { bfFromByteString       :: S.ByteString -> b-    , bfInsertLazyByteString :: L.ByteString -> b-    , bfToLazyByteString     :: b -> L.ByteString-    , bfInsertByteString     :: S.ByteString -> b-    , bfCopyByteString       :: S.ByteString -> b-    }--tester :: StreamingBuilder b => BufferAllocStrategy -> [b] -> IO [S.ByteString]+tester :: BufferAllocStrategy -> [Builder] -> IO [S.ByteString] tester strat builders0 = do     (recv, finish) <- newBuilderRecv strat     let loop front [] = do@@ -47,15 +37,14 @@             go front0     loop id builders0 -testerFlush :: StreamingBuilder b-            => BufferAllocStrategy -> [Maybe b] -> IO [Maybe S.ByteString]+testerFlush :: BufferAllocStrategy -> [Maybe Builder] -> IO [Maybe S.ByteString] testerFlush strat builders0 = do     (recv, finish) <- newBuilderRecv strat     let loop front [] = do             mbs <- finish             return $ front $ maybe [] (return . Just) mbs         loop front0 (mbu:bus) = do-            popper <- recv $ fromMaybe builderFlush mbu+            popper <- recv $ fromMaybe B.flush mbu             let go front = do                     bs <- popper                     if S.null bs@@ -67,55 +56,48 @@             go front0     loop id builders0 -builderSpec :: forall b. StreamingBuilder b => BuilderFunctions b -> Spec-builderSpec BuilderFunctions{..} = do+builderSpec :: Spec+builderSpec = do     prop "idempotent to toLazyByteString" $ \bss' -> do         let bss = map S.pack bss'-        let builders :: [b]-            builders = map bfFromByteString bss-        let lbs = bfToLazyByteString $ mconcat builders+        let builders = map B.byteString bss+        let lbs = B.toLazyByteString $ mconcat builders         outBss <- tester defaultStrategy builders         L.fromChunks outBss `shouldBe` lbs      it "works for large input" $ do-        let builders :: [b]-            builders = replicate 10000 (bfFromByteString "hello world!" :: b)-        let lbs = bfToLazyByteString $ mconcat builders+        let builders = replicate 10000 (B.byteString "hello world!")+        let lbs = B.toLazyByteString $ mconcat builders         outBss <- tester defaultStrategy builders         L.fromChunks outBss `shouldBe` lbs      it "works for lazy bytestring insertion" $ do-        let builders :: [b]-            builders = replicate 10000 (bfInsertLazyByteString "hello world!")-        let lbs = bfToLazyByteString $ mconcat builders+        let builders = replicate 10000 (B.lazyByteStringInsert "hello world!")+        let lbs = B.toLazyByteString $ mconcat builders         outBss <- tester defaultStrategy builders         L.fromChunks outBss `shouldBe` lbs      prop "works for strict bytestring insertion" $ \bs' -> do         let bs = S.pack bs'-        let builders :: [b]-            builders = replicate 10000 (bfCopyByteString bs `Data.Monoid.mappend` bfInsertByteString bs)-        let lbs = bfToLazyByteString $ mconcat builders+        let builders = replicate 10000 (B.byteStringCopy bs `Data.Monoid.mappend` B.byteStringInsert bs)+        let lbs = B.toLazyByteString $ mconcat builders         outBss <- tester defaultStrategy builders         L.fromChunks outBss `shouldBe` lbs      it "flush shouldn't bring in empty strings." $ do         let dat = ["hello", "world"]-            builders :: [b]-            builders = map ((`mappend` builderFlush) . bfFromByteString) dat+            builders = map ((`mappend` B.flush) . B.byteString) dat         out <- tester defaultStrategy builders         dat `shouldBe` out      prop "flushing" $ \bss' -> do         let bss = concatMap (\bs -> [Just $ S.pack bs, Nothing]) $ filter (not . null) bss'-        let builders :: [Maybe b]-            builders = map (fmap bfFromByteString) bss+        let builders = map (fmap B.byteString) bss         outBss <- testerFlush defaultStrategy builders         outBss `shouldBe` bss     it "large flush input" $ do         let lbs = L.pack $ concat $ replicate 100000 [0..255]-            chunks :: [Maybe b]-            chunks = map (Just . bfFromByteString) (L.toChunks lbs)+            chunks = map (Just . B.byteString) (L.toChunks lbs)         bss <- testerFlush defaultStrategy chunks         L.fromChunks (catMaybes bss) `shouldBe` lbs @@ -123,13 +105,7 @@ spec =     describe "Data.Streaming.ByteString.Builder" $ do -        builderSpec BuilderFunctions-            { bfFromByteString       = B.byteString-            , bfInsertLazyByteString = B.lazyByteStringInsert-            , bfToLazyByteString     = B.toLazyByteString-            , bfInsertByteString     = B.byteStringInsert-            , bfCopyByteString       = B.byteStringCopy-            }+        builderSpec          prop "toByteStringIO idempotent to toLazyByteString" $ \bss' -> do             let bss = mconcat (map (B.byteString . S.pack) bss')