Skip to content

Provide conversions between PosixPath and WindowsPath #214

Description

@Bodigrim

haskell/tar#88 introduces

-- | We assume UTF-8 on posix and UTF-16 on windows.
toWindowsPath :: MonadThrow m => PosixPath -> m WindowsPath
toWindowsPath posix = do
  str <- PFP.decodeUtf posix
  win <- WFP.encodeUtf str
  pure $ WS.map (\c -> if WFP.isPathSeparator c then WFP.pathSeparator else c) win

-- | We assume UTF-8 on posix and UTF-16 on windows.
toPosixPath :: MonadThrow m => WindowsPath -> m PosixPath
toPosixPath win = do
  str   <- WFP.decodeUtf win
  posix <- PFP.encodeUtf str
  pure $ PS.map (\c -> if PFP.isPathSeparator c then PFP.pathSeparator else c) posix

IMHO such utilities should better be provided by filepath itself, ideally optimized to a single pass without any intermediate structures.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions