Well typed and flexible file systems paths, preserving the OS and filesystem encoding.

You can choose the level of type safety you want. Path is the basic path type which can represent a file, directory, absolute or relative path with no restrictions. Depending on how much type safety you want you can choose appropriate type wrappers to wrap Path. File Path mandates the path to be a file whereas Abs (File Path) mandates it to be an absolute path representing a file.

You can upgrade or downgrade the safety. Whenever a less restrictive path type is converted to a more restrctive path type the conversion involves checks and it may fail. However, a more restrictive path type can be freely converted to a less restrictive one.

See the streamly-filepath package for interworking with the OsPath type. The Path type can be converted to and from OsPath type at zero cost since the underlying representation of both is the same.

Path Types

newtype Path Source #

A type representing file system paths for directories or files.

Constructors

Path (Array Word8) 
Instances
Instances details
IsPath Path Source # 
Instance details

Defined in Streamly.Internal.FileSystem.Path

IsPath (Abs (Dir Path)) Source # 
Instance details

Defined in Streamly.Internal.FileSystem.Path

IsPath (Abs (File Path)) Source # 
Instance details

Defined in Streamly.Internal.FileSystem.Path

IsPath (Abs Path) Source # 
Instance details

Defined in Streamly.Internal.FileSystem.Path

IsPath (Dir Path) Source # 
Instance details

Defined in Streamly.Internal.FileSystem.Path

IsPath (File Path) Source # 
Instance details

Defined in Streamly.Internal.FileSystem.Path

IsPath (Rel (Dir Path)) Source # 
Instance details

Defined in Streamly.Internal.FileSystem.Path

IsPath (Rel (File Path)) Source # 
Instance details

Defined in Streamly.Internal.FileSystem.Path

IsPath (Rel Path) Source # 
Instance details

Defined in Streamly.Internal.FileSystem.Path

data File a Source #

A type representing a file path.

data Dir a Source #

A type representing a directory path.

Instances
Instances details
IsPath (Abs (Dir Path)) Source # 
Instance details

Defined in Streamly.Internal.FileSystem.Path

IsPath (Dir Path) Source # 
Instance details

Defined in Streamly.Internal.FileSystem.Path

IsPath (Rel (Dir Path)) Source # 
Instance details

Defined in Streamly.Internal.FileSystem.Path

data Abs a Source #

A type representing absolute paths.

Instances
Instances details
IsPath (Abs (Dir Path)) Source # 
Instance details

Defined in Streamly.Internal.FileSystem.Path

IsPath (Abs (File Path)) Source # 
Instance details

Defined in Streamly.Internal.FileSystem.Path

IsPath (Abs Path) Source # 
Instance details

Defined in Streamly.Internal.FileSystem.Path

data Rel a Source #

A type representing relative paths.

Instances
Instances details
IsPath (Rel (Dir Path)) Source # 
Instance details

Defined in Streamly.Internal.FileSystem.Path

IsPath (Rel (File Path)) Source # 
Instance details

Defined in Streamly.Internal.FileSystem.Path

IsPath (Rel Path) Source # 
Instance details

Defined in Streamly.Internal.FileSystem.Path

Conversions

class IsPath a where Source #

A member of IsPath knows how to convert to and from the Path type.

Methods

fromPathUnsafe :: Path -> a Source #

Like fromPath but does not check the properties of Path. Provides performance and simplicity when we know that the properties of the path are already verified, for example, when we get the path from the file system or the OS APIs.

fromPath :: MonadThrow m => Path -> m a Source #

Convert a raw Path to other forms of well-typed paths. It may fail if the path does not satisfy the properties of the target type.

Path components may have limits. Total path length may have a limit.

toPath :: a -> Path Source #

Convert a well-typed path to a raw Path. Never fails.

Instances
Instances details
IsPath Path Source # 
Instance details

Defined in Streamly.Internal.FileSystem.Path

IsPath (Abs (Dir Path)) Source # 
Instance details

Defined in Streamly.Internal.FileSystem.Path

IsPath (Abs (File Path)) Source # 
Instance details

Defined in Streamly.Internal.FileSystem.Path

IsPath (Abs Path) Source # 
Instance details

Defined in Streamly.Internal.FileSystem.Path

IsPath (Dir Path) Source # 
Instance details

Defined in Streamly.Internal.FileSystem.Path

IsPath (File Path) Source # 
Instance details

Defined in Streamly.Internal.FileSystem.Path

IsPath (Rel (Dir Path)) Source # 
Instance details

Defined in Streamly.Internal.FileSystem.Path

IsPath (Rel (File Path)) Source # 
Instance details

Defined in Streamly.Internal.FileSystem.Path

IsPath (Rel Path) Source # 
Instance details

Defined in Streamly.Internal.FileSystem.Path

adaptPath :: (MonadThrow m, IsPath a, IsPath b) => a -> m b Source #

Convert a path type to another path type. This operation may fail with a PathException when converting a less restrictive path type to a more restrictive one.

Construction

fromChunk :: MonadThrow m => Array Word8 -> m Path Source #

On Posix it may fail if the byte array contains null characters. On Windows the array passed must be a multiple of 2 bytes as the underlying representation uses Word16.

Throws InvalidPath.

fromChunkUnsafe :: Array Word8 -> Path Source #

Unsafe: On Posix, a path cannot contain null characters. On Windows, the array passed must be a multiple of 2 bytes as the underlying representation uses Word16.

fromString :: MonadThrow m => [Char] -> m Path Source #

Encode a Unicode string to Path using strict UTF-8 encoding on Posix. On Posix it may fail if the stream contains null characters. TBD: Use UTF16LE on Windows.

fromChars :: MonadThrow m => Stream Identity Char -> m Path Source #

Encode a Unicode char stream to Path using strict UTF-8 encoding on Posix. On Posix it may fail if the stream contains null characters. TBD: Use UTF16LE on Windows.

Statically Verified Literals

path :: QuasiQuoter Source #

Generates a Path type from an interpolated string literal.

Unimplemented

abs :: QuasiQuoter Source #

Generates an Abs Path type from an interpolated string literal.

Unimplemented

rel :: QuasiQuoter Source #

Generates an Rel Path type from an interpolated string literal.

Unimplemented

dir :: QuasiQuoter Source #

Generates an Dir Path type from an interpolated string literal.

Unimplemented

file :: QuasiQuoter Source #

Generates an File Path type from an interpolated string literal.

Unimplemented

absdir :: QuasiQuoter Source #

Generates an Abs (Dir Path) type from an interpolated string literal.

Unimplemented

reldir :: QuasiQuoter Source #

Generates an Rel (Dir Path) type from an interpolated string literal.

Unimplemented

absfile :: QuasiQuoter Source #

Generates an Abs (File Path) type from an interpolated string literal.

Unimplemented

relfile :: QuasiQuoter Source #

Generates an Rel (File Path) type from an interpolated string literal.

Unimplemented

Statically Verified Strings

mkPath :: String -> Q Exp Source #

Generates a Path type.

Unimplemented

mkAbs :: String -> Q Exp Source #

Generates an Abs Path type.

Unimplemented

mkRel :: String -> Q Exp Source #

Generates an Rel Path type.

Unimplemented

mkDir :: String -> Q Exp Source #

Generates an Dir Path type.

Unimplemented

mkFile :: String -> Q Exp Source #

Generates an File Path type.

Unimplemented

mkAbsDir :: String -> Q Exp Source #

Generates an Abs (Dir Path) type.

Unimplemented

mkRelDir :: String -> Q Exp Source #

Generates an Rel (Dir Path) type.

Unimplemented

mkAbsFile :: String -> Q Exp Source #

Generates an Abs (File Path) type.

Unimplemented

mkRelFile :: String -> Q Exp Source #

Generates an Rel (File Path) type.

Unimplemented

Elimination

toChunk :: Path -> Array Word8 Source #

Convert Path to an array of bytes.

toString :: Path -> [Char] Source #

Decode the path to a Unicode string using strict UTF-8 decoding on Posix. TBD: Use UTF16LE on Windows.

toChars :: Monad m => Path -> Stream m Char Source #

Decode the path to a stream of Unicode chars using strict UTF-8 decoding on Posix. TBD: Use UTF16LE on Windows.

Operations

primarySeparator :: Char Source #

Primary path separator character, / on Posix and \ on Windows. Windows supports / too as a separator. Please use isSeparator for testing if a char is a separator char.

isSeparator :: Char -> Bool Source #

On Posix only / is a path separator but in windows it could be either / or \.

extendPath :: Path -> Path -> Path Source #

Like extendDir but for the less restrictive Path type which will always create a syntactically valid Path type but it may not be semantically valid because we may append an absolute path or we may append to a file path. The onus lies on the user to ensure that the first path is not a file and the second path is not absolute.

extendDir :: (IsPath (a (Dir Path)), IsPath b, IsPath (a b)) => a (Dir Path) -> Rel b -> a b Source #

Extend a directory path by appending a relative path to it. This is the equivalent to the / operator from the filepath package.