HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Moduleunliftio-0.2.25.1Haskell2010

UnliftIO.Temporary

Temporary file and directory support.

Strongly inspired by/stolen from the https://github.com/feuerbach/temporary package.

Copyright notice:

The following copyright notice is taken from https://github.com/feuerbach/temporary and is reproduced here as part of license terms of that package, of which this module is a derivate work.

Copyright
  (c) 2003-2006, Isaac Jones
  (c) 2005-2009, Duncan Coutts
  (c) 2008, Maximilian Bolingbroke
  ... and other contributors

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.
    * Neither the name of Maximilian Bolingbroke nor the names of other contributors may be used to
      endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 OWNER OR
CONTRIBUTORS 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.
  • 4 values
valuewithTempFile
  1. :: MonadUnliftIO m
  2. => FilePath

    Temp dir to create the file in.

  3. -> String

    File name template. See openTempFile.

  4. -> (FilePath -> Handle -> m a)

    Callback that can use the file.

  5. -> m a
#

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 -> do ...

The tmpFile will be file in the given directory, e.g. src/sdist.342.

valuewithTempDirectory
  1. :: MonadUnliftIO m
  2. => FilePath

    Temp directory to create the directory in.

  3. -> String

    Directory name template. See openTempFile.

  4. -> (FilePath -> m a)

    Callback that can use the directory.

  5. -> m a
#

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 -> do ...

The tmpDir will be a new subdirectory of the given directory, e.g. src/sdist.342.