@@ -11,17 +11,20 @@
1111
1212module Streamly.Internal.FileSystem.Dir
1313 (
14− -- ** Read from Directory
14+ -- * Streams
1515 read
1616 , readFiles
1717 , readDirs
1818 , readEither
1919 -- , readWithBufferOf
2020
21− , toStream
22− , toEither
23− , toFiles
24− , toDirs
21+ -- * Unfolds
22+ -- | Use the more convenient stream APIs instead of unfolds where possible.
23+ , reader
24+ , fileReader
25+ , dirReader
26+ , eitherReader
27+
2528 {-
2629 , toStreamWithBufferOf
2730
@@ -47,6 +50,11 @@ module Streamly.Internal.FileSystem.Dir
4750 , fromChunks
4851 , fromChunksWithBufferOf
4952 -}
53+ -- * Deprecated
54+ , toStream
55+ , toEither
56+ , toFiles
57+ , toDirs
5058 )
5159where
5260
@@ -186,9 +194,9 @@ toStreamWithBufferOf chunkSize h = AS.concat $ toChunksWithBufferOf chunkSize h
186194--
187195-- /Internal/
188196--
189−{-# INLINE read #-}
190−read :: MonadIO m => Unfold m String String
191−read =
197+{-# INLINE reader #-}
198+reader :: MonadIO m => Unfold m String String
199+reader =
192200 -- XXX use proper streaming read of the dir
193201 UF.lmapM (liftIO . Dir.getDirectoryContents) UF.fromList
194202
@@ -202,9 +210,9 @@ read =
202210--
203211-- /Internal/
204212--
205−{-# INLINE readEither #-}
206−readEither :: MonadIO m => Unfold m String (Either String String)
207−readEither =
213+{-# INLINE eitherReader #-}
214+eitherReader :: MonadIO m => Unfold m String (Either String String)
215+eitherReader =
208216 UF.mapM2 classify
209217 $ UF.filter (\x -> x /= "." && x /= "..")
210218 -- XXX use proper streaming read of the dir
@@ -219,48 +227,68 @@ readEither =
219227--
220228-- /Internal/
221229--
222−{-# INLINE readFiles #-}
223−readFiles :: MonadIO m => Unfold m String String
224−readFiles = fmap (fromRight undefined) $ UF.filter isRight readEither
230+{-# INLINE fileReader #-}
231+fileReader :: MonadIO m => Unfold m String String
232+fileReader = fmap (fromRight undefined) $ UF.filter isRight eitherReader
225233
226234-- | Read directories only. Filter out "." and ".." entries.
227235--
228236-- /Internal/
229237--
230−{-# INLINE readDirs #-}
231−readDirs :: MonadIO m => Unfold m String String
232−readDirs = fmap (fromLeft undefined) $ UF.filter isLeft readEither
238+{-# INLINE dirReader #-}
239+dirReader :: MonadIO m => Unfold m String String
240+dirReader = fmap (fromLeft undefined) $ UF.filter isLeft eitherReader
233241
234242-- | Raw read of a directory.
235243--
236244-- /Pre-release/
245+{-# INLINE read #-}
246+read :: MonadIO m => String -> Stream m String
247+read = S.unfold reader
248+
249+{-# DEPRECATED toStream "Please use 'read' instead" #-}
237250{-# INLINE toStream #-}
238251toStream :: MonadIO m => String -> Stream m String
239−toStream = S.unfold read
252+toStream = read
240253
241254-- | Read directories as Left and files as Right. Filter out "." and ".."
242255-- entries.
243256--
244257-- /Pre-release/
258+{-# INLINE readEither #-}
259+readEither :: MonadIO m => String -> Stream m (Either String String)
260+readEither = S.unfold eitherReader
261+
262+{-# DEPRECATED toEither "Please use 'readEither' instead" #-}
245263{-# INLINE toEither #-}
246264toEither :: MonadIO m => String -> Stream m (Either String String)
247−toEither = S.unfold readEither
265+toEither = readEither
248266
249267-- | Read files only.
250268--
251269-- /Internal/
252270--
271+{-# INLINE readFiles #-}
272+readFiles :: MonadIO m => String -> Stream m String
273+readFiles = S.unfold fileReader
274+
275+{-# DEPRECATED toFiles "Please use 'readFiles' instead" #-}
253276{-# INLINE toFiles #-}
254277toFiles :: MonadIO m => String -> Stream m String
255−toFiles = S.unfold readFiles
278+toFiles = readFiles
256279
257280-- | Read directories only.
258281--
259282-- /Internal/
260283--
284+{-# INLINE readDirs #-}
285+readDirs :: MonadIO m => String -> Stream m String
286+readDirs = S.unfold dirReader
287+
288+{-# DEPRECATED toDirs "Please use 'readDirs' instead" #-}
261289{-# INLINE toDirs #-}
262290toDirs :: MonadIO m => String -> Stream m String
263−toDirs = S.unfold readDirs
291+toDirs = readDirs
264292
265293{-
266294-------------------------------------------------------------------------------