@@ -11,17 +11,20 @@
12module Streamly.Internal.FileSystem.Dir
12module Streamly.Internal.FileSystem.Dir
14− -- ** Read from Directory
14+ -- * Streams
16 , readFiles
16 , readFiles
17 , readDirs
17 , readDirs
18 , readEither
18 , readEither
19 -- , readWithBufferOf
19 -- , readWithBufferOf
21− , toStream
21+ -- * Unfolds
22− , toEither
22+ -- | Use the more convenient stream APIs instead of unfolds where possible.
23− , toFiles
23+ , reader
24− , toDirs
24+ , fileReader
26 , toStreamWithBufferOf
29 , toStreamWithBufferOf
@@ -47,6 +50,11 @@ module Streamly.Internal.FileSystem.Dir
47 , fromChunks
50 , fromChunks
48 , fromChunksWithBufferOf
51 , fromChunksWithBufferOf
@@ -186,9 +194,9 @@ toStreamWithBufferOf chunkSize h = AS.concat $ toChunksWithBufferOf chunkSize h
187-- /Internal/
195-- /Internal/
189−{-# INLINE read #-}
197+{-# INLINE reader #-}
190−read :: MonadIO m => Unfold m String String
198+reader :: MonadIO m => Unfold m String String
192 -- XXX use proper streaming read of the dir
200 -- XXX use proper streaming read of the dir
193 UF.lmapM (liftIO . Dir.getDirectoryContents) UF.fromList
201 UF.lmapM (liftIO . Dir.getDirectoryContents) UF.fromList
@@ -202,9 +210,9 @@ read =
203-- /Internal/
211-- /Internal/
205−{-# INLINE readEither #-}
213+{-# INLINE eitherReader #-}
206−readEither :: MonadIO m => Unfold m String (Either String String)
214+eitherReader :: MonadIO m => Unfold m String (Either String String)
207−readEither =
215+eitherReader =
208 UF.mapM2 classify
216 UF.mapM2 classify
209 $ UF.filter (\x -> x /= "." && x /= "..")
217 $ UF.filter (\x -> x /= "." && x /= "..")
210 -- XXX use proper streaming read of the dir
218 -- XXX use proper streaming read of the dir
@@ -219,48 +227,68 @@ readEither =
220-- /Internal/
228-- /Internal/
222−{-# INLINE readFiles #-}
230+{-# INLINE fileReader #-}
223−readFiles :: MonadIO m => Unfold m String String
231+fileReader :: MonadIO m => Unfold m String String
224−readFiles = fmap (fromRight undefined) $ UF.filter isRight readEither
232+fileReader = fmap (fromRight undefined) $ UF.filter isRight eitherReader
226-- | Read directories only. Filter out "." and ".." entries.
234-- | Read directories only. Filter out "." and ".." entries.
228-- /Internal/
236-- /Internal/
230−{-# INLINE readDirs #-}
238+{-# INLINE dirReader #-}
231−readDirs :: MonadIO m => Unfold m String String
239+dirReader :: MonadIO m => Unfold m String String
232−readDirs = fmap (fromLeft undefined) $ UF.filter isLeft readEither
240+dirReader = fmap (fromLeft undefined) $ UF.filter isLeft eitherReader
234-- | Raw read of a directory.
242-- | Raw read of a directory.
236-- /Pre-release/
244-- /Pre-release/
246+read :: MonadIO m => String -> Stream m String
247+read = S.unfold reader
249+{-# DEPRECATED toStream "Please use 'read' instead" #-}
237{-# INLINE toStream #-}
250{-# INLINE toStream #-}
238toStream :: MonadIO m => String -> Stream m String
251toStream :: MonadIO m => String -> Stream m String
239−toStream = S.unfold read
252+toStream = read
241-- | Read directories as Left and files as Right. Filter out "." and ".."
254-- | Read directories as Left and files as Right. Filter out "." and ".."
242-- entries.
255-- entries.
244-- /Pre-release/
257-- /Pre-release/
258+{-# INLINE readEither #-}
259+readEither :: MonadIO m => String -> Stream m (Either String String)
260+readEither = S.unfold eitherReader
262+{-# DEPRECATED toEither "Please use 'readEither' instead" #-}
245{-# INLINE toEither #-}
263{-# INLINE toEither #-}
246toEither :: MonadIO m => String -> Stream m (Either String String)
264toEither :: MonadIO m => String -> Stream m (Either String String)
247−toEither = S.unfold readEither
265+toEither = readEither
249-- | Read files only.
267-- | Read files only.
251-- /Internal/
269-- /Internal/
271+{-# INLINE readFiles #-}
272+readFiles :: MonadIO m => String -> Stream m String
273+readFiles = S.unfold fileReader
275+{-# DEPRECATED toFiles "Please use 'readFiles' instead" #-}
253{-# INLINE toFiles #-}
276{-# INLINE toFiles #-}
254toFiles :: MonadIO m => String -> Stream m String
277toFiles :: MonadIO m => String -> Stream m String
255−toFiles = S.unfold readFiles
278+toFiles = readFiles
257-- | Read directories only.
280-- | Read directories only.
259-- /Internal/
282-- /Internal/
284+{-# INLINE readDirs #-}
285+readDirs :: MonadIO m => String -> Stream m String
286+readDirs = S.unfold dirReader
288+{-# DEPRECATED toDirs "Please use 'readDirs' instead" #-}
261{-# INLINE toDirs #-}
289{-# INLINE toDirs #-}
262toDirs :: MonadIO m => String -> Stream m String
290toDirs :: MonadIO m => String -> Stream m String
263−toDirs = S.unfold readDirs
291+toDirs = readDirs
266-------------------------------------------------------------------------------
294-------------------------------------------------------------------------------