on master help sign in
Move Streamly.FileSystem.Handle to streamly-core

And some formatting changes.

commitf609af1d014e834eab48b902829462afcce88b7c authorRanjeet Kumar Ranjan <ranjeetr@composewell.com> dateThu 22 Sep 2022, 17:30 (4 years ago) parente718389
7 files changed+43−65
src/Streamly/FileSystem/Handle.hs → core/src/Streamly/FileSystem/Handle.hs src/Streamly/Internal/FileSystem/Handle.hs → core/src/Streamly/Internal/FileSystem/Handle.hs+9−13 core/src/Streamly/Internal/Unicode/Array/Char.hs+4−4 core/src/Streamly/Internal/Unicode/Stream.hs+10−9 core/streamly-core.cabal+5−4 src/Streamly/Internal/FileSystem/Dir.hs+13−33 streamly.cabal+2−2
src/Streamly/FileSystem/Handle.hs → core/src/Streamly/FileSystem/Handle.hsrenamed

The content is the same.

src/Streamly/Internal/FileSystem/Handle.hs → core/src/Streamly/Internal/FileSystem/Handle.hsrenamed+9−13
@@ -131,10 +131,8 @@ import Streamly.Internal.System.IO (defaultChunkSize)
131131import qualified Streamly.Data.Fold as FL
132132import qualified Streamly.Data.Array.Unboxed as A
133133import qualified Streamly.Internal.Data.Array.Unboxed.Type as A
134− (byteLength, asPtrUnsafe)
135−import qualified Streamly.Internal.Data.Array.Unboxed.Mut as MArray
136− (Array(..), newPinnedArrayBytes, asPtrUnsafe)
137134import qualified Streamly.Internal.Data.Array.Stream.Foreign as AS
135+import qualified Streamly.Internal.Data.Array.Unboxed.Mut.Type as MArray
138136import qualified Streamly.Internal.Data.Refold.Type as Refold
139137import qualified Streamly.Internal.Data.Fold.Type as FL(refoldMany)
140138import qualified Streamly.Internal.Data.Stream as S
@@ -212,8 +210,7 @@ getChunkOf = undefined
212210-- read may be less than or equal to @size@.
213211-- @since 0.9.0
214212{-# INLINE _getChunksWith #-}
215−_getChunksWith :: (MonadIO m)
216− => Int -> Handle -> Stream m (Array Word8)
213+_getChunksWith :: MonadIO m => Int -> Handle -> Stream m (Array Word8)
217214_getChunksWith size h = S.fromStreamK go
218215 where
219216 -- XXX use cons/nil instead
@@ -231,8 +228,7 @@ _getChunksWith size h = S.fromStreamK go
231228--
232229-- @since 0.9.0
233230{-# INLINE_NORMAL getChunksWith #-}
234−getChunksWith :: (MonadIO m) =>
235− Int -> Handle -> Stream m (Array Word8)
231+getChunksWith :: MonadIO m => Int -> Handle -> Stream m (Array Word8)
236232getChunksWith size h = S.fromStreamD (D.Stream step ())
237233 where
238234 {-# INLINE_LATE step #-}
@@ -313,7 +309,7 @@ readChunksFromToWith = Unfold step inject
313309--
314310-- @since 0.9.0
315311{-# INLINE getChunks #-}
316−getChunks :: (MonadIO m) => Handle -> Stream m (Array Word8)
312+getChunks :: MonadIO m => Handle -> Stream m (Array Word8)
317313getChunks = getChunksWith defaultChunkSize
318314
319315-- | Unfolds a handle into a stream of 'Word8' arrays. Requests to the IO
@@ -362,7 +358,7 @@ readWithBufferOf = readWith
362358--
363359-- /Pre-release/
364360{-# INLINE getBytesWith #-}
365−getBytesWith :: (MonadIO m) => Int -> Handle -> Stream m Word8
361+getBytesWith :: MonadIO m => Int -> Handle -> Stream m Word8
366362getBytesWith size h = AS.concat $ getChunksWith size h
367363
368364-- TODO
@@ -386,7 +382,7 @@ read = UF.many A.read readChunks
386382--
387383-- /Pre-release/
388384{-# INLINE getBytes #-}
389−getBytes :: (MonadIO m) => Handle -> Stream m Word8
385+getBytes :: MonadIO m => Handle -> Stream m Word8
390386getBytes = AS.concat . getChunks
391387
392388-------------------------------------------------------------------------------
@@ -600,7 +596,7 @@ write = toHandleWith A.defaultChunkSize
600596--
601597-- @since 0.7.0
602598{-# INLINE readUtf8 #-}
603−readUtf8 :: (MonadIO m) => Handle -> Stream m Char
599+readUtf8 :: MonadIO m => Handle -> Stream m Char
604600readUtf8 = decodeUtf8 . read
605601
606602-- |
@@ -622,7 +618,7 @@ writeUtf8 h s = write h $ encodeUtf8 s
622618--
623619-- @since 0.7.0
624620{-# INLINE writeUtf8ByLines #-}
625−writeUtf8ByLines :: (MonadIO m) => Handle -> Stream m Char -> m ()
621+writeUtf8ByLines :: MonadIO m => Handle -> Stream m Char -> m ()
626622writeUtf8ByLines = undefined
627623
628624-- | Read UTF-8 lines from a file handle and apply the specified fold to each
@@ -630,7 +626,7 @@ writeUtf8ByLines = undefined
630626--
631627-- @since 0.7.0
632628{-# INLINE readLines #-}
633−readLines :: (MonadIO m) => Handle -> Fold m Char b -> Stream m b
629+readLines :: MonadIO m => Handle -> Fold m Char b -> Stream m b
634630readLines h f = foldLines (readUtf8 h) f
635631
636632-------------------------------------------------------------------------------
core/src/Streamly/Internal/Unicode/Array/Char.hs+4−4
@@ -42,7 +42,7 @@ import Prelude hiding (String, lines, words, unlines, unwords)
4242-- ["lines","this","string","",""]
4343--
4444{-# INLINE lines #-}
45−lines :: (MonadIO m) => Stream m Char -> Stream m (Array Char)
45+lines :: MonadIO m => Stream m Char -> Stream m (Array Char)
4646lines = S.lines A.write
4747
4848-- | Break a string up into a stream of strings, which were delimited
@@ -54,7 +54,7 @@ lines = S.lines A.write
5454-- ["A","newline","is","considered","white","space?"]
5555--
5656{-# INLINE words #-}
57−words :: (MonadIO m) => Stream m Char -> Stream m (Array Char)
57+words :: MonadIO m => Stream m Char -> Stream m (Array Char)
5858words = S.words A.write
5959
6060-- | Flattens the stream of @Array Char@, after appending a terminating
@@ -71,7 +71,7 @@ words = S.words A.write
7171--
7272-- > unlines . lines /= id
7373{-# INLINE unlines #-}
74−unlines :: (MonadIO m) => Stream m (Array Char) -> Stream m Char
74+unlines :: MonadIO m => Stream m (Array Char) -> Stream m Char
7575unlines = S.unlines A.read
7676
7777-- | Flattens the stream of @Array Char@, after appending a separating
@@ -88,5 +88,5 @@ unlines = S.unlines A.read
8888--
8989-- > unwords . words /= id
9090{-# INLINE unwords #-}
91−unwords :: (MonadIO m) => Stream m (Array Char) -> Stream m Char
91+unwords :: MonadIO m => Stream m (Array Char) -> Stream m Char
9292unwords = S.unwords A.read
core/src/Streamly/Internal/Unicode/Stream.hs+10−9
@@ -830,8 +830,7 @@ decodeUtf8ArraysD = decodeUtf8ArraysWithD TransliterateCodingFailure
830830--
831831-- /Pre-release/
832832{-# INLINE decodeUtf8Arrays #-}
833−decodeUtf8Arrays ::
834− (MonadIO m) => Stream m (Array Word8) -> Stream m Char
833+decodeUtf8Arrays :: MonadIO m => Stream m (Array Word8) -> Stream m Char
835834decodeUtf8Arrays =
836835 fromStreamD . decodeUtf8ArraysD . toStreamD
837836
@@ -846,7 +845,7 @@ decodeUtf8ArraysD' = decodeUtf8ArraysWithD ErrorOnCodingFailure
846845--
847846-- /Pre-release/
848847{-# INLINE decodeUtf8Arrays' #-}
849−decodeUtf8Arrays' :: (MonadIO m) => Stream m (Array Word8) -> Stream m Char
848+decodeUtf8Arrays' :: MonadIO m => Stream m (Array Word8) -> Stream m Char
850849decodeUtf8Arrays' = fromStreamD . decodeUtf8ArraysD' . toStreamD
851850
852851{-# INLINE decodeUtf8ArraysD_ #-}
@@ -861,7 +860,7 @@ decodeUtf8ArraysD_ = decodeUtf8ArraysWithD DropOnCodingFailure
861860-- /Pre-release/
862861{-# INLINE decodeUtf8Arrays_ #-}
863862decodeUtf8Arrays_ ::
864− (MonadIO m) => Stream m (Array Word8) -> Stream m Char
863+ MonadIO m => Stream m (Array Word8) -> Stream m Char
865864decodeUtf8Arrays_ =
866865 fromStreamD . decodeUtf8ArraysD_ . toStreamD
867866
@@ -1025,7 +1024,7 @@ encodeObject encode u = Stream.fold Array.write . encode . Stream.unfold u
10251024--
10261025-- /Internal/
10271026{-# INLINE encodeObjects #-}
1028−encodeObjects :: (MonadIO m) =>
1027+encodeObjects :: MonadIO m =>
10291028 (Stream m Char -> Stream m Word8)
10301029 -> Unfold m a Char
10311030 -> Stream m a
@@ -1037,8 +1036,10 @@ encodeObjects encode u = Stream.mapM (encodeObject encode u)
10371036--
10381037-- @since 0.8.0
10391038{-# INLINE encodeStrings #-}
1040−encodeStrings :: (MonadIO m) =>
1041− (Stream m Char -> Stream m Word8) -> Stream m String -> Stream m (Array Word8)
1039+encodeStrings :: MonadIO m =>
1040+ (Stream m Char -> Stream m Word8)
1041+ -> Stream m String
1042+ -> Stream m (Array Word8)
10421043encodeStrings encode = encodeObjects encode Unfold.fromList
10431044
10441045{-
@@ -1116,7 +1117,7 @@ words f m = Stream.fromStreamD $ D.wordsBy isSpace f (Stream.toStreamD m)
11161117--
11171118-- /Pre-release/
11181119{-# INLINE unlines #-}
1119−unlines :: (MonadIO m) => Unfold m a Char -> Stream m a -> Stream m Char
1120+unlines :: MonadIO m => Unfold m a Char -> Stream m a -> Stream m Char
11201121unlines = Stream.interposeSuffix '\n'
11211122
11221123-- | Unfold the elements of a stream to character streams using the supplied
@@ -1130,5 +1131,5 @@ unlines = Stream.interposeSuffix '\n'
11301131--
11311132-- /Pre-release/
11321133{-# INLINE unwords #-}
1133−unwords :: (MonadIO m) => Unfold m a Char -> Stream m a -> Stream m Char
1134+unwords :: MonadIO m => Unfold m a Char -> Stream m a -> Stream m Char
11341135unwords = Stream.interpose ' '
core/streamly-core.cabal+5−4
@@ -324,15 +324,17 @@ library
324324 , Streamly.Internal.Data.Array.Unboxed
325325 , Streamly.Internal.Data.Array.Stream.Mut.Foreign
326326 , Streamly.Internal.Data.Array.Stream.Fold.Foreign
327−
328327 , Streamly.Internal.Data.Array.Stream.Foreign
329−
328+
330329 -- streamly-unicode
331330 , Streamly.Internal.Unicode.Stream
332331 , Streamly.Internal.Unicode.String
333332 , Streamly.Internal.Unicode.Char.Parser
334333 , Streamly.Internal.Unicode.Array.Char
335334
335+ -- Filesystem/IO
336+ , Streamly.Internal.FileSystem.Handle
337+
336338 -- Ring Arrays
337339 , Streamly.Internal.Data.Ring.Foreign
338340 , Streamly.Internal.Data.Ring
@@ -349,9 +351,8 @@ library
349351 , Streamly.Data.Unfold
350352 , Streamly.Data.Array.Unboxed
351353 , Streamly.Data.Array.Unboxed.Mut
352−
353− -- Text Processing
354354 , Streamly.Unicode.Stream
355+ , Streamly.FileSystem.Handle
355356
356357 if flag(dev)
357358 exposed-modules:
src/Streamly/Internal/FileSystem/Dir.hs+13−33
@@ -52,34 +52,16 @@ where
5252
5353import Control.Monad.IO.Class (MonadIO(..))
5454import Data.Either (isRight, isLeft, fromLeft, fromRight)
55−-- import Data.Word (Word8)
56−-- import Foreign.ForeignPtr (withForeignPtr)
57−-- import Foreign.ForeignPtr.Unsafe (unsafeForeignPtrToPtr)
58−-- import Foreign.Ptr (minusPtr, plusPtr)
59−-- import Foreign.Storable (Storable(..))
60−-- import GHC.ForeignPtr (mallocPlainForeignPtrBytes)
61−-- import System.IO (Handle, hGetBufSome, hPutBuf)
62−import Prelude hiding (read)
63−
64−-- import Streamly.Data.Fold (Fold)
55+import Streamly.Data.Stream (Stream)
6556import Streamly.Internal.Data.Unfold.Type (Unfold(..))
66−-- import Streamly.Internal.Data.Array.Unboxed.Type
67−-- (Array(..), writeNUnsafe, defaultChunkSize, shrinkToFit,
68−-- lpackArraysChunksOf)
69−-- import Streamly.Internal.Data.Stream (Stream)
70−import Streamly.Internal.Data.Stream.IsStream.Type (IsStream)
71−-- import Streamly.String (encodeUtf8, decodeUtf8, foldLines)
72−
73−-- import qualified Streamly.Data.Fold as FL
74−-- import qualified Streamly.Internal.Data.Fold.Type as FL
57+
7558import qualified Streamly.Data.Unfold as UF
7659import qualified Streamly.Internal.Data.Unfold as UF (mapM2)
77−-- import qualified Streamly.Internal.Data.Array.Stream.Foreign as AS
78−import qualified Streamly.Internal.Data.Stream.IsStream as S
79−-- import qualified Streamly.Data.Array.Unboxed as A
80−-- import qualified Streamly.Internal.Data.Stream.StreamD.Type as D
60+import qualified Streamly.Data.Stream as S
8161import qualified System.Directory as Dir
8262
63+import Prelude hiding (read)
64+
8365{-
8466{-# INLINABLE readArrayUpto #-}
8567readArrayUpto :: Int -> Handle -> IO (Array Word8)
@@ -104,8 +86,7 @@ readArrayUpto size h = do
10486-- The maximum size of a single array is specified by @size@. The actual size
10587-- read may be less than or equal to @size@.
10688{-# INLINE _toChunksWithBufferOf #-}
107−_toChunksWithBufferOf :: (IsStream t, MonadIO m)
108− => Int -> Handle -> t m (Array Word8)
89+_toChunksWithBufferOf :: MonadIO m => Int -> Handle -> Stream m (Array Word8)
10990_toChunksWithBufferOf size h = go
11091 where
11192 -- XXX use cons/nil instead
@@ -121,7 +102,7 @@ _toChunksWithBufferOf size h = go
121102--
122103-- @since 0.7.0
123104{-# INLINE_NORMAL toChunksWithBufferOf #-}
124−toChunksWithBufferOf :: (IsStream t, MonadIO m) => Int -> Handle -> t m (Array Word8)
105+toChunksWithBufferOf :: MonadIO m => Int -> Handle -> Stream m (Array Word8)
125106toChunksWithBufferOf size h = D.fromStreamD (D.Stream step ())
126107 where
127108 {-# INLINE_LATE step #-}
@@ -161,7 +142,7 @@ readChunksWithBufferOf = Unfold step return
161142--
162143-- @since 0.7.0
163144{-# INLINE toChunks #-}
164−toChunks :: (IsStream t, MonadIO m) => Handle -> t m (Array Word8)
145+toChunks :: MonadIO m => Handle -> Stream m (Array Word8)
165146toChunks = toChunksWithBufferOf defaultChunkSize
166147
167148-- | Unfolds a handle into a stream of 'Word8' arrays. Requests to the IO
@@ -196,7 +177,7 @@ readWithBufferOf = UF.many readChunksWithBufferOf A.read
196177--
197178-- /Pre-release/
198179{-# INLINE toStreamWithBufferOf #-}
199−toStreamWithBufferOf :: (IsStream t, MonadIO m) => Int -> Handle -> t m Word8
180+toStreamWithBufferOf :: MonadIO m => Int -> Handle -> Stream m Word8
200181toStreamWithBufferOf chunkSize h = AS.concat $ toChunksWithBufferOf chunkSize h
201182-}
202183
@@ -254,7 +235,7 @@ readDirs = fmap (fromLeft undefined) $ UF.filter isLeft readEither
254235--
255236-- /Pre-release/
256237{-# INLINE toStream #-}
257−toStream :: (IsStream t, MonadIO m) => String -> t m String
238+toStream :: MonadIO m => String -> Stream m String
258239toStream = S.unfold read
259240
260241-- | Read directories as Left and files as Right. Filter out "." and ".."
@@ -262,8 +243,7 @@ toStream = S.unfold read
262243--
263244-- /Pre-release/
264245{-# INLINE toEither #-}
265−toEither :: (IsStream t, MonadIO m)
266− => String -> t m (Either String String)
246+toEither :: MonadIO m => String -> Stream m (Either String String)
267247toEither = S.unfold readEither
268248
269249-- | Read files only.
@@ -271,7 +251,7 @@ toEither = S.unfold readEither
271251-- /Internal/
272252--
273253{-# INLINE toFiles #-}
274−toFiles :: (IsStream t, MonadIO m) => String -> t m String
254+toFiles :: MonadIO m => String -> Stream m String
275255toFiles = S.unfold readFiles
276256
277257-- | Read directories only.
@@ -279,7 +259,7 @@ toFiles = S.unfold readFiles
279259-- /Internal/
280260--
281261{-# INLINE toDirs #-}
282−toDirs :: (IsStream t, MonadIO m) => String -> t m String
262+toDirs :: MonadIO m => String -> Stream m String
283263toDirs = S.unfold readDirs
284264
285265{-
streamly.cabal+2−2
@@ -219,8 +219,10 @@ extra-source-files:
219219 core/src/Streamly/Data/Unbox.hs
220220 core/src/Streamly/Data/Array/Unboxed.hs
221221 core/src/Streamly/Data/Array/Unboxed/Mut.hs
222+ core/src/Streamly/FileSystem/Handle.hs
222223 core/src/Streamly/Internal/Data/Time/Clock/Darwin.c
223224 core/src/Streamly/Internal/Data/Time/Clock/Windows.c
225+ core/src/Streamly/Internal/FileSystem/Handle.hs
224226 core/src/Streamly/Internal/Unicode/Array/Char.hs
225227 core/src/Streamly/Internal/Unicode/Char/Parser.hs
226228 core/src/Streamly/Internal/Unicode/Stream.hs
@@ -491,7 +493,6 @@ library
491493 , Streamly.Internal.Unicode.Char
492494
493495 -- streamly-filesystem
494− , Streamly.Internal.FileSystem.Handle
495496 , Streamly.Internal.FileSystem.Dir
496497 , Streamly.Internal.FileSystem.File
497498
@@ -506,7 +507,6 @@ library
506507 , Streamly.Prelude
507508
508509 -- Filesystem/IO
509− , Streamly.FileSystem.Handle
510510 , Streamly.Console.Stdio
511511
512512 -- Network/IO