Loading...

Streamly.Internal.FileSystem.WindowsPath

This module implements a WindowsPath type representing a file system path for Windows operating systems. The only assumption about the encoding of the path is that it maps the characters /, \ and . to Word16 representing their ASCII values. Operations are provided to encode and decode using UTF-16LE encoding.

Type

newtype WindowsPath Source #

A type representing file system paths on Windows.

A WindowsPath is validated before construction unless unsafe constructors are used to create it. For validations performed by the safe construction methods see the fromChars function.

Note that in some cases the file system may perform unicode normalization on paths (e.g. Apple HFS), it may cause surprising results as the path used by the user may not have the same bytes as later returned by the file system.

Constructors

WindowsPath (Array Word16) 
Instances
Instances details
IsPath WindowsPath WindowsPath Source # 
Instance details

Defined in Streamly.Internal.FileSystem.WindowsPath

IsPath WindowsPath (Dir WindowsPath) Source # 
Instance details

Defined in Streamly.Internal.FileSystem.WindowsPath.Node

IsPath WindowsPath (File WindowsPath) Source # 
Instance details

Defined in Streamly.Internal.FileSystem.WindowsPath.Node

IsPath WindowsPath (Branch WindowsPath) Source # 
Instance details

Defined in Streamly.Internal.FileSystem.WindowsPath.Seg

IsPath WindowsPath (Branch (Dir WindowsPath)) Source # 
Instance details

Defined in Streamly.Internal.FileSystem.WindowsPath.SegNode

IsPath WindowsPath (Branch (File WindowsPath)) Source # 
Instance details

Defined in Streamly.Internal.FileSystem.WindowsPath.SegNode

IsPath WindowsPath (Rooted WindowsPath) Source # 
Instance details

Defined in Streamly.Internal.FileSystem.WindowsPath.Seg

IsPath WindowsPath (Rooted (Dir WindowsPath)) Source # 
Instance details

Defined in Streamly.Internal.FileSystem.WindowsPath.SegNode

IsPath WindowsPath (Rooted (File WindowsPath)) Source # 
Instance details

Defined in Streamly.Internal.FileSystem.WindowsPath.SegNode

Conversions

class IsPath a b where Source #

If the type a b is a member of IsPath it means we know how to convert the type b to and from the base type a.

Methods

unsafeFromPath :: a -> b Source #

Like fromPath but does not check the properties of Path. The user is responsible to maintain the invariants enforced by the type b otherwise surprising behavior may result.

This operation 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 from the OS APIs.

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

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

toPath :: b -> a Source #

Convert a well-typed path to the base path type. Never fails.

Instances
Instances details
IsPath PosixPath PosixPath Source # 
Instance details

Defined in Streamly.Internal.FileSystem.PosixPath

IsPath WindowsPath WindowsPath Source # 
Instance details

Defined in Streamly.Internal.FileSystem.WindowsPath

IsPath PosixPath (Dir PosixPath) Source # 
Instance details

Defined in Streamly.Internal.FileSystem.PosixPath.Node

IsPath PosixPath (File PosixPath) Source # 
Instance details

Defined in Streamly.Internal.FileSystem.PosixPath.Node

IsPath PosixPath (Branch PosixPath) Source # 
Instance details

Defined in Streamly.Internal.FileSystem.PosixPath.Seg

IsPath PosixPath (Branch (Dir PosixPath)) Source # 
Instance details

Defined in Streamly.Internal.FileSystem.PosixPath.SegNode

IsPath PosixPath (Branch (File PosixPath)) Source # 
Instance details

Defined in Streamly.Internal.FileSystem.PosixPath.SegNode

IsPath PosixPath (Rooted PosixPath) Source # 
Instance details

Defined in Streamly.Internal.FileSystem.PosixPath.Seg

IsPath PosixPath (Rooted (Dir PosixPath)) Source # 
Instance details

Defined in Streamly.Internal.FileSystem.PosixPath.SegNode

IsPath PosixPath (Rooted (File PosixPath)) Source # 
Instance details

Defined in Streamly.Internal.FileSystem.PosixPath.SegNode

IsPath WindowsPath (Dir WindowsPath) Source # 
Instance details

Defined in Streamly.Internal.FileSystem.WindowsPath.Node

IsPath WindowsPath (File WindowsPath) Source # 
Instance details

Defined in Streamly.Internal.FileSystem.WindowsPath.Node

IsPath WindowsPath (Branch WindowsPath) Source # 
Instance details

Defined in Streamly.Internal.FileSystem.WindowsPath.Seg

IsPath WindowsPath (Branch (Dir WindowsPath)) Source # 
Instance details

Defined in Streamly.Internal.FileSystem.WindowsPath.SegNode

IsPath WindowsPath (Branch (File WindowsPath)) Source # 
Instance details

Defined in Streamly.Internal.FileSystem.WindowsPath.SegNode

IsPath WindowsPath (Rooted WindowsPath) Source # 
Instance details

Defined in Streamly.Internal.FileSystem.WindowsPath.Seg

IsPath WindowsPath (Rooted (Dir WindowsPath)) Source # 
Instance details

Defined in Streamly.Internal.FileSystem.WindowsPath.SegNode

IsPath WindowsPath (Rooted (File WindowsPath)) Source # 
Instance details

Defined in Streamly.Internal.FileSystem.WindowsPath.SegNode

adapt :: (MonadThrow m, IsPath WindowsPath a, IsPath WindowsPath 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. This can be used to upgrade or downgrade type safety.

Validation

Construction

fromChunk :: (MonadThrow m, IsPath WindowsPath a) => Array Word8 -> m a Source #

See fromChars for failure cases.

unsafeFromChunk :: IsPath WindowsPath a => Array Word8 -> a Source #

Unsafe: The user is responsible to make sure that the cases mentioned in WindowsPath are satisfied.

fromString :: (MonadThrow m, IsPath WindowsPath a) => [Char] -> m a Source #

See fromChars.

>>> fromString = Path.fromChars . Stream.fromList

Statically Verified String Literals

Quasiquoters.

path :: QuasiQuoter Source #

Generates a WindowsPath type from a quoted literal.

>>> Path.toString ([path|/usr/bin|] :: PosixPath)
"/usr/bin"

Statically Verified Strings

Template Haskell expression splices.

pathE :: String -> Q Exp Source #

Generates a Haskell expression of type WindowsPath from a String.

Elimination

toChunk :: IsPath WindowsPath a => a -> Array Word8 Source #

Convert the path to an array of bytes.

toChars :: (Monad m, IsPath WindowsPath a) => a -> Stream m Char Source #

Decode the path to a stream of Unicode chars using strict UTF-16LE decoding.

toChars_ :: (Monad m, IsPath WindowsPath a) => a -> Stream m Char Source #

Decode the path to a stream of Unicode chars using lax UTF-16LE decoding.

toString :: IsPath WindowsPath a => a -> [Char] Source #

Decode the path to a Unicode string using strict UTF-16LE decoding.

toString_ :: IsPath WindowsPath a => a -> [Char] Source #

Decode the path to a Unicode string using strict UTF-16LE decoding.

Separators

dropTrailingSeparators :: WindowsPath -> WindowsPath Source #

If the path is // the result is /. If it is a// then the result is a.

Tests

isRooted :: WindowsPath -> Bool Source #

A path that is attached to a root. "C:" is considered an absolute root and "." as a dynamic root. ".." is not considered a root, "..x" or "xy" are not rooted paths.

Absolute locations:

  • C:\ local drive
  • \\server\ UNC server
  • \\?\C:\ Long UNC local drive
  • \\?\UNC\ Long UNC remote server
  • \\.\ DOS local device namespace
  • \\??\ DOS global namespace

Relative locations:

  • \ relative to current drive root
  • .\ relative to current directory
  • C:file relative to current directory in drive

isBranch :: WindowsPath -> Bool Source #

A path that is not attached to a root e.g. a/b/c or ../b/c.

>>> isBranch = not . Path.isRooted

Joining

append :: WindowsPath -> WindowsPath -> WindowsPath Source #

Append a WindowsPath to another. Fails if the second path refers to a rooted path and not a branch. Use unsafeAppend to avoid failure if you know it is ok to append the path or use the typesafe Streamly.FileSystem.OS_PATH.Seg module.

>>> Path.toString $ Path.append [path|/usr|] [path|bin|]
"/usr/bin"

append' :: WindowsPath -> WindowsPath -> WindowsPath Source #

A stricter version of append which requires the first path to be a directory like path i.e. with a trailing separator.

Splitting

Equality

data EqCfg Source #

Options for path comparison operation. By default path comparison uses a strict criteria for equality. The following options are provided to control the strictness.

Constructors

EqCfg 

Fields