hpath: Support for well-typed paths

[ bsd3, filesystem ] [ Propose Tags ]

Support for well-typed paths, utilizing ByteString under the hood.


[Skip to Readme]

Downloads

Note: This package has metadata revisions in the cabal description newer than included in the tarball. To unpack the package including the revisions, use 'cabal get'.

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.5.9, 0.6.0, 0.7.0, 0.7.1, 0.7.2, 0.7.3, 0.7.4, 0.7.5, 0.8.0, 0.8.1, 0.9.0, 0.9.1, 0.9.2, 0.10.0, 0.10.1, 0.10.2, 0.11.0, 0.12.0, 0.12.1 (info)
Change log CHANGELOG
Dependencies base (>=4.2 && <5), bytestring (>=0.9.2.0), deepseq, exceptions, hspec, simple-sendfile (>=0.2.24), unix (>=2.5), unix-bytestring, utf8-string, word8 [details]
License BSD-3-Clause
Copyright Julian Ospald 2016
Author Julian Ospald <hasufell@posteo.de>
Maintainer Julian Ospald <hasufell@posteo.de>
Revised Revision 1 made by GeorgeWilson at 2018-04-12T00:21:46Z
Category Filesystem
Source repo head: git clone https://github.com/hasufell/hpath
Uploaded by maerwald at 2016-06-03T22:43:18Z
Distributions NixOS:0.12.1
Reverse Dependencies 4 direct, 1 indirect [details]
Downloads 7761 total (65 in the last 30 days)
Rating 2.0 (votes: 1) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2016-06-03 [all 1 reports]

Readme for hpath-0.7.5

[back to package description]

HPath

Gitter chat Hackage version Build Status

Support for well-typed paths in Haskell. Also provides ByteString based filepath manipulation.

Motivation

The motivation came during development of hsfm which has a pretty strict File type, but lacks a strict Path type, e.g. for user input.

The library that came closest to my needs was path, but the API turned out to be oddly complicated for my use case, so I decided to fork it.

Similarly, posix-paths was exactly what I wanted for the low-level operations, but upstream seems dead, so it is forked as well and merged into this library.

Goals

  • well-typed paths
  • high-level API to file operations like recursive directory copy
  • safe filepath manipulation, never using String as filepath, but ByteString
  • still allowing sufficient control to interact with the underlying low-level calls

Note: this library was written for posix systems and it will probably not support other systems.

Differences to 'path'

  • doesn't attempt to fake IO-related information into the path, so whether a path points to a file or directory is up to your IO-code to decide...
  • trailing path separators will be preserved if they exist, no messing with that
  • uses safe ByteString for filepaths under the hood instead of unsafe String
  • fixes broken dirname
  • renames dirname/filename to basename/dirname to match the POSIX shell functions
  • introduces a new Path Fn for safe filename guarantees and a RelC class
  • allows pattern matching via unidirectional PatternSynonym
  • uses simple doctest for testing
  • allows ~/ as relative path, because on posix level ~ is just a regular filename that does NOT point to $HOME
  • remove TH, it sucks

Differences to 'posix-paths'

  • uses the word8 package for save word8 literals instead of OverloadedStrings
  • hasTrailingPathSeparator and dropTrailingPathSeparator behave in the same way as their System.FilePath counterpart
  • added various functions:
    • equalFilePath
    • getSearchPath
    • hasParentDir
    • hiddenFile
    • isFileName
    • isValid
    • makeRelative
    • makeValid
    • normalise
    • splitSearchPath
    • stripExtension
  • has a custom versions of openFd which allows more control over the flags than its unix package counterpart
  • adds a getDirectoryContents' version that works on Fd

Examples in ghci

Start ghci via cabal repl:

-- enable OverloadedStrings
:set -XOverloadedStrings
-- import HPath.IO
import HPath.IO
-- parse an absolute path
abspath <- parseAbs "/home"
-- parse a relative path (e.g. user users home directory)
relpath <- parseRel "jule"
-- concatenate paths
let newpath = abspath </> relpath
-- get file type
getFileType newpath
-- return all contents of that directory
getDirsFiles newpath
-- return all contents of the parent directory
getDirsFiles (dirname newpath)