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
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.
Convert a well-typed path to the base path type. Never fails.
Instances
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
validatePath :: MonadThrow m => WindowsPath -> m () Source #
validatePath' :: MonadThrow m => WindowsPath -> m () Source #
isValidPath :: WindowsPath -> Bool Source #
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.
fromChars :: (MonadThrow m, IsPath WindowsPath a) => Stream Identity Char -> m a Source #
fromString :: (MonadThrow m, IsPath WindowsPath a) => [Char] -> m a Source #
See fromChars.
>>>
fromString = Path.fromChars . Stream.fromList
unsafeFromString :: IsPath WindowsPath a => [Char] -> a Source #
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.
Elimination
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 directoryC: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
unsafeAppend :: WindowsPath -> WindowsPath -> WindowsPath Source #
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
splitRoot :: WindowsPath -> (WindowsPath, WindowsPath) Source #
splitPath :: Monad m => WindowsPath -> Stream m WindowsPath Source #
splitPath_ :: Monad m => WindowsPath -> Stream m WindowsPath Source #
splitFile :: WindowsPath -> (WindowsPath, WindowsPath) Source #
splitExtension :: WindowsPath -> (WindowsPath, WindowsPath) Source #
Equality
eqPath :: WindowsPath -> WindowsPath -> Bool 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
|
eqPathWith :: EqCfg -> WindowsPath -> WindowsPath -> Bool Source #
eqPathBytes :: WindowsPath -> WindowsPath -> Bool Source #