Merge pull request #1503 from ncaq/add-file-source-bytes
added: fileSourceByteString
This commit is contained in:
commit
5861357923
@ -1,3 +1,7 @@
|
||||
## 1.6.5
|
||||
|
||||
* Add `fileSourceByteString` [#1503](https://github.com/yesodweb/yesod/pull/1503)
|
||||
|
||||
## 1.6.4
|
||||
|
||||
* Add `addContentDispositionFileName` [#1504](https://github.com/yesodweb/yesod/pull/1504)
|
||||
|
||||
@ -47,6 +47,7 @@ module Yesod.Core.Handler
|
||||
, fileName
|
||||
, fileContentType
|
||||
, fileSource
|
||||
, fileSourceByteString
|
||||
, fileMove
|
||||
-- *** Convenience functions
|
||||
, languages
|
||||
@ -253,6 +254,7 @@ import Data.CaseInsensitive (CI, original)
|
||||
import qualified Data.Conduit.List as CL
|
||||
import Control.Monad.Trans.Resource (MonadResource, InternalState, runResourceT, withInternalState, getInternalState, liftResourceT, resourceForkIO)
|
||||
import qualified System.PosixCompat.Files as PC
|
||||
import Conduit ((.|), runConduit, sinkLazy)
|
||||
import Data.Conduit (ConduitT, transPipe, Flush (Flush), yield, Void)
|
||||
import qualified Yesod.Core.TypeCache as Cache
|
||||
import qualified Data.Word8 as W8
|
||||
@ -1381,6 +1383,17 @@ rawRequestBody = do
|
||||
fileSource :: MonadResource m => FileInfo -> ConduitT () S.ByteString m ()
|
||||
fileSource = transPipe liftResourceT . fileSourceRaw
|
||||
|
||||
-- | Extract a strict `ByteString` body from a `FileInfo`.
|
||||
--
|
||||
-- This function will block while reading the file.
|
||||
--
|
||||
-- > do
|
||||
-- > fileByteString <- fileSourceByteString fileInfo
|
||||
--
|
||||
-- @since 1.6.5
|
||||
fileSourceByteString :: MonadResource m => FileInfo -> m S.ByteString
|
||||
fileSourceByteString fileInfo = runConduit (L.toStrict <$> (fileSource fileInfo .| sinkLazy))
|
||||
|
||||
-- | Provide a pure value for the response body.
|
||||
--
|
||||
-- > respond ct = return . TypedContent ct . toContent
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
name: yesod-core
|
||||
version: 1.6.4
|
||||
version: 1.6.5
|
||||
license: MIT
|
||||
license-file: LICENSE
|
||||
author: Michael Snoyman <michael@snoyman.com>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user