packages feed

streaming-wai (empty) → 0.1.0

raw patch · 4 files changed

+119/−0 lines, 4 filesdep +basedep +bytestringdep +bytestring-buildersetup-changed

Dependencies added: base, bytestring, bytestring-builder, http-types, streaming, wai

Files

+ LICENSE view
@@ -0,0 +1,20 @@+Streaming Wai utilities+Copyright (C) 2015 William Casarin++Permission is hereby granted, free of charge, to any person obtaining+a copy of this software and associated documentation files (the "Software"),+to deal in the Software without restriction, including without limitation+the rights to use, copy, modify, merge, publish, distribute, sublicense,+and/or sell copies of the Software, and to permit persons to whom the+Software is furnished to do so, subject to the following conditions:++The above copyright notice and this permission notice shall be included+in all copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,+DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE+OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ src/Network/Wai/Streaming.hs view
@@ -0,0 +1,62 @@+{-# LANGUAGE DeriveFunctor #-}++module Network.Wai.Streaming ( Flush(..)+                             -- * ByteStrings+                             , streamingResponse+                             , streamingBody++                             -- * Flushed Builders+                             -- $flush+                             , streamingResponseF+                             , streamingBodyF+                             ) where++import Streaming+import Network.Wai+import Data.ByteString (ByteString)+import Data.ByteString.Builder (byteString, Builder)+import Network.HTTP.Types.Header+import Network.HTTP.Types.Status+import Streaming.Prelude as S++data Flush a = Chunk !a+             | Flush+             deriving (Show, Functor)+++-- | Stream strict 'ByteString's into a 'Response'+streamingResponse :: Stream (Of ByteString) IO r+                  -> Status+                  -> ResponseHeaders+                  -> Response+streamingResponse src status headers =+  responseStream status headers (streamingBody src)+++-- | Stream strict 'ByteString's into a 'StreamingBody'+streamingBody :: Stream (Of ByteString) IO r -> StreamingBody+streamingBody src write flush = S.foldM_ writer flush return src+  where+    writer _ a = do+      write (byteString a)+      flush++-- $flush+--+-- Using Flush allows you to explicitly control flushing behavior++-- | Stream 'Builder's into a 'Response'+streamingResponseF :: Stream (Of (Flush Builder)) IO r+                   -> Status+                   -> ResponseHeaders+                   -> Response+streamingResponseF src status headers =+  responseStream status headers (streamingBodyF src)+++-- | Stream 'Builder's into a 'StreamingBody'+streamingBodyF :: Stream (Of (Flush Builder)) IO r -> StreamingBody+streamingBodyF src write flush = S.foldM_ writer flush return src+  where+    writer _ (Chunk a) = write a+    writer _ Flush     = flush
+ streaming-wai.cabal view
@@ -0,0 +1,35 @@+name:          streaming-wai+version:       0.1.0+synopsis:      Streaming Wai utilities+description:   Please see README.md+homepage:      http://github.com/jb55/streaming-wai+license:       MIT+license-file:  LICENSE+author:        William Casarin+maintainer:    bill@casarin.me+copyright:     2015 William Casarin+category:      Web+build-type:    Simple++tested-with: GHC == 7.6.3+           , GHC == 7.8.4+           , GHC == 7.10.2+           , GHC == 7.10.3++-- extra-source-files:+cabal-version:       >=1.10++library+  hs-source-dirs:      src+  exposed-modules:     Network.Wai.Streaming+  build-depends: base >= 4.6 && < 5+               , http-types+               , wai+               , bytestring+               , bytestring-builder+               , streaming+  default-language:    Haskell2010++source-repository head+  type:     git+  location: https://github.com/jb55/streaming-wai