summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIvanMiljenovic <>2017-07-07 04:57:00 (GMT)
committerhdiff <hdiff@hdiff.luite.com>2017-07-07 04:57:00 (GMT)
commit0d7e032d502d9295ee9b83b6069247e5f1074194 (patch)
tree6486c66bdd4acc840b70ae010b2473d4d80684f0
parent7fa41e2d631ee0e366e31b18819d8e6d8d7b53e4 (diff)
version 0.1.1.00.1.1.0
-rw-r--r--ChangeLog.md13
-rw-r--r--src/Streaming/With.hs72
-rw-r--r--src/Streaming/With/Lifted.hs76
-rw-r--r--streaming-with.cabal3
4 files changed, 156 insertions, 8 deletions
diff --git a/ChangeLog.md b/ChangeLog.md
index 9059853..433d6ab 100644
--- a/ChangeLog.md
+++ b/ChangeLog.md
@@ -1,5 +1,16 @@
# Revision history for streaming-with
-## 0.1.0.0 -- 2017-06-30
+## 0.1.1.0 -- 2017-07-07
+
+* Add support for the [temporary] package, specifically the functions:
+
+ * `withSystemTempFile`
+ * `withTempFile`
+ * `withSystemTempDirectory`
+ * `withTempDirectory`
+
+ [temporary]: http://hackage.haskell.org/package/temporary
+
+## 0.1.0.0 -- 2017-06-30
* First release.
diff --git a/src/Streaming/With.hs b/src/Streaming/With.hs
index 36d16dd..48a5484 100644
--- a/src/Streaming/With.hs
+++ b/src/Streaming/With.hs
@@ -16,7 +16,14 @@ module Streaming.With
, writeBinaryFile
, appendBinaryFile
, withBinaryFileContents
- -- ** Re-exports
+ -- ** Temporary files
+ , withSystemTempFile
+ , withTempFile
+ -- *** Re-exports
+ -- $tempreexports
+ , withSystemTempDirectory
+ , withTempDirectory
+ -- * Re-exports
-- $reexports
, MonadMask
, bracket
@@ -25,10 +32,13 @@ module Streaming.With
import Data.ByteString.Streaming (ByteString)
import qualified Data.ByteString.Streaming as B
-import Control.Monad.Catch (MonadMask, bracket)
-import Control.Monad.IO.Class (MonadIO, liftIO)
-import System.IO (Handle, IOMode(..), hClose, openBinaryFile,
- openFile)
+import Control.Monad.Catch (MonadMask, bracket)
+import Control.Monad.IO.Class (MonadIO, liftIO)
+import System.IO (Handle, IOMode(..), hClose,
+ openBinaryFile, openFile)
+import System.IO.Temp (withSystemTempDirectory,
+ withTempDirectory)
+import qualified System.IO.Temp as T
--------------------------------------------------------------------------------
@@ -62,6 +72,58 @@ withBinaryFileContents fp f = withBinaryFile fp ReadMode (f . B.hGetContents)
--------------------------------------------------------------------------------
+-- | /This is 'T.withSystemTempFile' from the @temporary@ package with
+-- the continuation re-structured to only take one argument./
+--
+-- Create and use a temporary file in the system standard temporary
+-- directory.
+--
+-- Behaves exactly the same as 'withTempFile', except that the
+-- parent temporary directory will be that returned by
+-- 'T.getCanonicalTemporaryDirectory'.
+--
+-- @since 0.1.1.0
+withSystemTempFile :: (MonadIO m, MonadMask m)
+ => String -- ^ File name template. See 'T.openTempFile'
+ -> ((FilePath, Handle) -> m r)
+ -> m r
+withSystemTempFile template = T.withSystemTempFile template . curry
+
+-- | /This is 'T.withTempFile' from the @temporary@ package with
+-- the continuation re-structured to only take one argument./
+--
+-- Use a temporary filename that doesn't already exist.
+--
+-- Creates a new temporary file inside the given directory, making
+-- use of the template. The temp file is deleted after use. For
+-- example:
+--
+-- > withTempFile "src" "sdist." $ \(tmpFile, hFile) -> ...
+--
+-- The @tmpFile@ will be file in the given directory, e.g.
+-- @src/sdist.342@.
+--
+-- @since 0.1.1.0
+withTempFile :: (MonadIO m, MonadMask m)
+ => FilePath -- ^ Temp dir to create the file in
+ -> String -- ^ File name template. See
+ -- 'T.openTempFile'.
+ -> ((FilePath, Handle) -> m r)
+ -> m r
+withTempFile dir template = T.withTempFile dir template . curry
+
+{- $tempreexports
+
+These functions are re-exported from the
+<http://hackage.haskell.org/package/temporary temporary> package as-is
+as their structure already matches those found here.
+
+@since 0.1.1.0
+
+-}
+
+--------------------------------------------------------------------------------
+
{- $reexports
These may assist in writing your own bracket-style functions.
diff --git a/src/Streaming/With/Lifted.hs b/src/Streaming/With/Lifted.hs
index b6fc215..7918356 100644
--- a/src/Streaming/With/Lifted.hs
+++ b/src/Streaming/With/Lifted.hs
@@ -44,7 +44,12 @@ module Streaming.With.Lifted
, writeBinaryFile
, appendBinaryFile
, withBinaryFileContents
- -- ** Re-exports
+ -- ** Temporary files
+ , withSystemTempFile
+ , withTempFile
+ , withSystemTempDirectory
+ , withTempDirectory
+ -- * Re-exports
-- $reexports
, MonadMask
, bracket
@@ -125,6 +130,75 @@ withBinaryFileContents fp = liftWith (W.withBinaryFileContents fp)
--------------------------------------------------------------------------------
+-- | Create and use a temporary file in the system standard temporary
+-- directory.
+--
+-- Behaves exactly the same as 'withTempFile', except that the
+-- parent temporary directory will be that returned by
+-- 'System.IO.Temp.getCanonicalTemporaryDirectory'.
+--
+-- @since 0.1.1.0
+withSystemTempFile :: (Withable w)
+ => String -- ^ File name template. See
+ -- 'System.IO.Temp.openTempFile'.
+ -> w (FilePath, Handle)
+withSystemTempFile template = liftWith (W.withSystemTempFile template)
+
+-- | Use a temporary filename that doesn't already exist.
+--
+-- Creates a new temporary file inside the given directory, making
+-- use of the template. The temp file is deleted after use. For
+-- example:
+--
+-- > withTempFile "src" "sdist." >>= \(tmpFile, hFile) -> ...
+--
+-- The @tmpFile@ will be file in the given directory, e.g.
+-- @src/sdist.342@.
+--
+-- @since 0.1.1.0
+withTempFile :: (Withable w)
+ => FilePath -- ^ Temp dir to create the file in
+ -> String -- ^ File name template. See
+ -- 'System.IO.Temp.openTempFile'.
+ -> w (FilePath, Handle)
+withTempFile dir template = liftWith (W.withTempFile dir template)
+
+-- | Create and use a temporary directory in the system standard
+-- temporary directory.
+--
+-- Behaves exactly the same as 'withTempDirectory', except that the
+-- parent temporary directory will be that returned by
+-- 'System.IO.Temp.getCanonicalTemporaryDirectory'.
+--
+-- @since 0.1.1.0
+withSystemTempDirectory :: (Withable w)
+ => String -- ^ Directory name template. See
+ -- 'System.IO.Temp.openTempFile'.
+ -> w FilePath
+withSystemTempDirectory template = liftWith (W.withSystemTempDirectory template)
+
+-- | Create and use a temporary directory.
+--
+-- Creates a new temporary directory inside the given directory,
+-- making use of the template. The temp directory is deleted after
+-- use. For example:
+--
+-- > withTempDirectory "src" "sdist." >>= \tmpDir -> ...
+--
+-- The @tmpDir@ will be a new subdirectory of the given directory, e.g.
+-- @src/sdist.342@.
+--
+-- @since 0.1.1.0
+withTempDirectory :: (Withable w)
+ => FilePath -- ^ Temp directory to create the
+ -- directory in
+ -> String -- ^ Directory name template. See
+ -- 'System.IO.Temp.openTempFile'.
+ -> w FilePath
+withTempDirectory dir template = liftWith (W.withTempDirectory dir template)
+
+--------------------------------------------------------------------------------
+
{- $reexports
These may assist in writing your own bracket-style functions.
diff --git a/streaming-with.cabal b/streaming-with.cabal
index a7013f8..8daeb92 100644
--- a/streaming-with.cabal
+++ b/streaming-with.cabal
@@ -1,5 +1,5 @@
name: streaming-with
-version: 0.1.0.0
+version: 0.1.1.0
synopsis: with/bracket-style idioms for use with streaming
description:
This package provides the foundations for a continuation-based
@@ -26,6 +26,7 @@ library
, exceptions >= 0.6 && < 0.9
, managed == 1.0.*
, streaming-bytestring >= 0.1.0.3 && < 0.2
+ , temporary >= 1.2.1 && < 1.3
, transformers
hs-source-dirs: src
default-language: Haskell2010