Skip to content

Commit 3ca4efd

Browse files
Change the signature of toChunk in Path module
1 parent 494f848 commit 3ca4efd

3 files changed

Lines changed: 16 additions & 38 deletions

File tree

core/src/Streamly/Internal/FileSystem/Path/Common.hs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ module Streamly.Internal.FileSystem.Path.Common
2828
, mkQ
2929

3030
-- * Elimination
31-
, toChunk
3231
, toString
3332
, toChars
3433

@@ -1206,11 +1205,6 @@ fromChunk Windows arr =
12061205
Just x -> validatePath Windows x >> pure x
12071206
-}
12081207

1209-
-- | Convert 'Path' to an array of bytes.
1210-
{-# INLINE toChunk #-}
1211-
toChunk :: Array a -> Array Word8
1212-
toChunk = Array.asBytes
1213-
12141208
{-# INLINE unsafeFromChars #-}
12151209
unsafeFromChars :: (Unbox a) =>
12161210
(Stream Identity Char -> Stream Identity a)

core/src/Streamly/Internal/FileSystem/PosixPath.hs

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -166,13 +166,11 @@ import Control.Monad.Catch (MonadThrow(..))
166166
import Data.Bifunctor (bimap)
167167
import Data.Functor.Identity (Identity(..))
168168
import Data.Maybe (fromJust)
169-
import Data.Word (Word8)
170-
#if defined(IS_WINDOWS)
171-
import Data.Word (Word16)
172-
#endif
173169
#ifndef IS_WINDOWS
170+
import Data.Word (Word8)
174171
import Foreign.C (CString)
175172
#else
173+
import Data.Word (Word16)
176174
import Foreign.C (CWString)
177175
#endif
178176
import Language.Haskell.TH.Syntax (lift)
@@ -304,11 +302,7 @@ addTrailingSeparator p = unsafeAppend p sep
304302

305303
-- | Throws an exception if the path is not valid. See 'isValidPath' for the
306304
-- list of validations.
307-
#ifndef IS_WINDOWS
308-
validatePath :: MonadThrow m => Array Word8 -> m ()
309-
#else
310-
validatePath :: MonadThrow m => Array Word16 -> m ()
311-
#endif
305+
validatePath :: MonadThrow m => Array WORD_TYPE -> m ()
312306
validatePath = Common.validatePath Common.OS_NAME
313307

314308
#ifndef IS_WINDOWS
@@ -322,7 +316,7 @@ validatePath = Common.validatePath Common.OS_NAME
322316
-- >>> isValid "\0"
323317
-- False
324318
--
325-
isValidPath :: Array Word8 -> Bool
319+
isValidPath :: Array WORD_TYPE -> Bool
326320
isValidPath = Common.isValidPath Common.OS_NAME
327321
#endif
328322

@@ -342,11 +336,7 @@ isValidPath = Common.isValidPath Common.OS_NAME
342336
-- per 'isValidPath'.
343337
--
344338
{-# INLINE unsafeFromChunk #-}
345-
#ifndef IS_WINDOWS
346-
unsafeFromChunk :: IsPath OS_PATH a => Array Word8 -> a
347-
#else
348-
unsafeFromChunk :: IsPath OS_PATH a => Array Word16 -> a
349-
#endif
339+
unsafeFromChunk :: IsPath OS_PATH a => Array WORD_TYPE -> a
350340
unsafeFromChunk =
351341
#ifndef DEBUG
352342
unsafeFromPath . OS_PATH . Common.unsafeFromChunk
@@ -359,11 +349,7 @@ unsafeFromChunk =
359349
-- | Convert a byte array into a Path.
360350
-- Throws 'InvalidPath' if 'isValidPath' fails on the path.
361351
--
362-
#ifndef IS_WINDOWS
363-
fromChunk :: (MonadThrow m, IsPath OS_PATH a) => Array Word8 -> m a
364-
#else
365-
fromChunk :: (MonadThrow m, IsPath OS_PATH a) => Array Word16 -> m a
366-
#endif
352+
fromChunk :: (MonadThrow m, IsPath OS_PATH a) => Array WORD_TYPE -> m a
367353
fromChunk arr = Common.fromChunk Common.OS_NAME arr >>= fromPath . OS_PATH
368354

369355
-- XXX Should be a Fold instead?
@@ -391,11 +377,7 @@ fromChars s =
391377

392378
-- | Create a raw path i.e. an array representing the path. Note that the path
393379
-- is not validated, therefore, it may not be valid according to 'isValidPath'.
394-
#ifndef IS_WINDOWS
395-
rawFromString :: [Char] -> Array Word8
396-
#else
397-
rawFromString :: [Char] -> Array Word16
398-
#endif
380+
rawFromString :: [Char] -> Array WORD_TYPE
399381
rawFromString =
400382
Common.unsafeFromChars Unicode.UNICODE_ENCODER
401383
. Stream.fromList
@@ -472,9 +454,9 @@ path = mkQ pathE
472454

473455
-- XXX unPath?
474456

475-
-- | Convert the path to an array of bytes.
476-
toChunk :: IsPath OS_PATH a => a -> Array Word8
477-
toChunk p = let OS_PATH arr = toPath p in Common.toChunk arr
457+
-- | Convert the path to an array.
458+
toChunk :: IsPath OS_PATH a => a -> Array WORD_TYPE
459+
toChunk p = let OS_PATH arr = toPath p in arr
478460

479461
-- | Decode the path to a stream of Unicode chars using strict CODEC_NAME decoding.
480462
{-# INLINE toChars #-}

core/src/Streamly/Internal/FileSystem/WindowsPath.hs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,19 +146,21 @@ For APIs that have not been released yet.
146146
-- True
147147
-- >>> isValid "\\\\??\\x"
148148
-- True
149-
isValidPath :: Array Word16 -> Bool
149+
isValidPath :: Array WORD_TYPE -> Bool
150150
isValidPath = Common.isValidPath Common.OS_NAME
151151

152152
-- | Like 'validatePath' on but more strict. A share root must be followed by a
153153
-- non-empty path. Thus "\/\/x\/" is not considered a valid path.
154-
validatePath' :: MonadThrow m => Array Word16 -> m ()
154+
validatePath' ::
155+
MonadThrow m => Array WORD_TYPE -> m ()
155156
validatePath' = Common.validatePath' Common.Windows
156157

157158
-- | Like 'isValidPath' but more strict, see validatePath' for differences.
158-
isValidPath' :: Array Word16 -> Bool
159+
isValidPath' ::
160+
Array WORD_TYPE -> Bool
159161
isValidPath' = Common.isValidPath' Common.Windows
160162

161-
-- | Read a raw array of Word16 as a path type.
163+
-- | Read a raw array of WORD_TYPE as a path type.
162164
--
163165
-- >>> readRaw = fromJust . Path.fromChunk . read
164166
--

0 commit comments

Comments
 (0)