@@ -56,6 +56,7 @@ module Streamly.Internal.FileSystem.OS_PATH
5656 , unsafeFromChunk
5757 , fromChars
5858 , fromString
59+ , rawFromString
5960 , unsafeFromString
6061 -- , fromCString#
6162 -- , fromW16CString#
@@ -169,7 +170,6 @@ For APIs that have not been released yet.
169170>>> import Data.Either (Either, isLeft)
170171>>> import Control.Exception (SomeException, evaluate, try)
171172
172- >>> rawFromString = Array.fromPureStream . Unicode.encodeUtf8' . Stream.fromList
173173>>> pack = fromJust . Path.fromString
174174>>> fails action = (try (evaluate action) :: IO (Either SomeException String)) >>= return . isLeft
175175-}
@@ -253,7 +253,7 @@ validatePath = Common.validatePath Common.OS_NAME
253253-- | Check if the filepath is valid i.e. does the operating system or the file
254254-- system allow such a path in listing or creating files?
255255--
256- -- >>> isValid = Path.isValidPath . rawFromString
256+ -- >>> isValid = Path.isValidPath . Path. rawFromString
257257--
258258-- >>> isValid ""
259259-- False
@@ -327,15 +327,25 @@ fromChars s =
327327 Common. fromChars Common. OS_NAME Unicode. UNICODE_ENCODER s
328328 >>= fromPath . OS_PATH
329329
330+ -- | Create a raw path i.e. an array representing the path. Note that the path
331+ -- is not validated, therefore, it may not be valid according to 'isValidPath'.
332+ #ifndef IS_WINDOWS
333+ rawFromString :: [Char ] -> Array Word8
334+ #else
335+ rawFromString :: [Char ] -> Array Word16
336+ #endif
337+ rawFromString =
338+ Common. unsafeFromChars Unicode. UNICODE_ENCODER
339+ . Stream. fromList
340+
330341-- | Like 'fromString' but does not perform any validations mentioned under
331342-- 'isValidPath'. Fails only if unicode encoding fails.
332343unsafeFromString :: IsPath OS_PATH a => [Char ] -> a
333344unsafeFromString =
334345#ifndef DEBUG
335346 unsafeFromPath
336347 . OS_PATH
337- . Common. unsafeFromChars Unicode. UNICODE_ENCODER
338- . Stream. fromList
348+ . rawFromString
339349#else
340350 fromJust . fromString
341351#endif
@@ -432,7 +442,7 @@ showRaw p =
432442--
433443-- >>> readRaw = fromJust . Path.fromChunk . read
434444--
435- -- >>> arr = rawFromString "hello"
445+ -- >>> arr = Path. rawFromString "hello"
436446-- >>> Path.showRaw $ (Path.readRaw $ show arr :: Path.PosixPath)
437447-- "fromList [104,101,108,108,111]"
438448--
0 commit comments