Skip to content

Commit

Permalink
Document unsafePerformIO and FilePath conversions.
Browse files Browse the repository at this point in the history
  • Loading branch information
luke-clifton authored and Bodigrim committed Aug 17, 2021
1 parent 1010c9e commit 05a09c3
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Data/ByteString.hs
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,10 @@ unpackFoldr bs k z = foldr k z bs
-- that allow arbitrary bytes in their paths. This conversion
-- function does the same thing that `System.IO.openFile` would
-- do when decoding the 'FilePath'.
--
-- This function is in 'IO' because the file system encoding can be
-- changed. If the encoding can be assumed to be constant in your
-- use case, you may invoke this function via 'unsafePerformIO'.
fromFilePath :: FilePath -> IO ByteString
fromFilePath path = do
enc <- getFileSystemEncoding
Expand All @@ -342,6 +346,10 @@ fromFilePath path = do
-- This function uses the file system encoding, and resulting 'FilePath's
-- can be safely used with standard IO functions and will reference the
-- correct path in the presence of arbitrary non-UTF-8 encoded paths.
--
-- This function is in 'IO' because the file system encoding can be
-- changed. If the encoding can be assumed to be constant in your
-- use case, you may invoke this function via 'unsafePerformIO'.
toFilePath :: ByteString -> IO FilePath
toFilePath path = do
enc <- getFileSystemEncoding
Expand Down

0 comments on commit 05a09c3

Please sign in to comment.