@@ -52,34 +52,16 @@ where
53import Control.Monad.IO.Class (MonadIO(..))
53import Control.Monad.IO.Class (MonadIO(..))
54import Data.Either (isRight, isLeft, fromLeft, fromRight)
54import 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)
64−-- import Streamly.Data.Fold (Fold)
55+import Streamly.Data.Stream (Stream)
65import Streamly.Internal.Data.Unfold.Type (Unfold(..))
56import Streamly.Internal.Data.Unfold.Type (Unfold(..))
66−-- import Streamly.Internal.Data.Array.Unboxed.Type
57+
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)
73−-- import qualified Streamly.Data.Fold as FL
74−-- import qualified Streamly.Internal.Data.Fold.Type as FL
75import qualified Streamly.Data.Unfold as UF
58import qualified Streamly.Data.Unfold as UF
76import qualified Streamly.Internal.Data.Unfold as UF (mapM2)
59import 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
60+import qualified Streamly.Data.Stream as S
79−-- import qualified Streamly.Data.Array.Unboxed as A
80−-- import qualified Streamly.Internal.Data.Stream.StreamD.Type as D
81import qualified System.Directory as Dir
61import qualified System.Directory as Dir
63+import Prelude hiding (read)
84{-# INLINABLE readArrayUpto #-}
66{-# INLINABLE readArrayUpto #-}
85readArrayUpto :: Int -> Handle -> IO (Array Word8)
67readArrayUpto :: Int -> Handle -> IO (Array Word8)
@@ -104,8 +86,7 @@ readArrayUpto size h = do
104-- The maximum size of a single array is specified by @size@. The actual size
86-- The maximum size of a single array is specified by @size@. The actual size
105-- read may be less than or equal to @size@.
87-- read may be less than or equal to @size@.
106{-# INLINE _toChunksWithBufferOf #-}
88{-# INLINE _toChunksWithBufferOf #-}
107−_toChunksWithBufferOf :: (IsStream t, MonadIO m)
89+_toChunksWithBufferOf :: MonadIO m => Int -> Handle -> Stream m (Array Word8)
108− => Int -> Handle -> t m (Array Word8)
109_toChunksWithBufferOf size h = go
90_toChunksWithBufferOf size h = go
111 -- XXX use cons/nil instead
92 -- XXX use cons/nil instead
@@ -121,7 +102,7 @@ _toChunksWithBufferOf size h = go
122-- @since 0.7.0
103-- @since 0.7.0
123{-# INLINE_NORMAL toChunksWithBufferOf #-}
104{-# 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)
125toChunksWithBufferOf size h = D.fromStreamD (D.Stream step ())
106toChunksWithBufferOf size h = D.fromStreamD (D.Stream step ())
127 {-# INLINE_LATE step #-}
108 {-# INLINE_LATE step #-}
@@ -161,7 +142,7 @@ readChunksWithBufferOf = Unfold step return
162-- @since 0.7.0
143-- @since 0.7.0
163{-# INLINE toChunks #-}
144{-# INLINE toChunks #-}
164−toChunks :: (IsStream t, MonadIO m) => Handle -> t m (Array Word8)
145+toChunks :: MonadIO m => Handle -> Stream m (Array Word8)
165toChunks = toChunksWithBufferOf defaultChunkSize
146toChunks = toChunksWithBufferOf defaultChunkSize
167-- | Unfolds a handle into a stream of 'Word8' arrays. Requests to the IO
148-- | Unfolds a handle into a stream of 'Word8' arrays. Requests to the IO
@@ -196,7 +177,7 @@ readWithBufferOf = UF.many readChunksWithBufferOf A.read
197-- /Pre-release/
178-- /Pre-release/
198{-# INLINE toStreamWithBufferOf #-}
179{-# INLINE toStreamWithBufferOf #-}
199−toStreamWithBufferOf :: (IsStream t, MonadIO m) => Int -> Handle -> t m Word8
180+toStreamWithBufferOf :: MonadIO m => Int -> Handle -> Stream m Word8
200toStreamWithBufferOf chunkSize h = AS.concat $ toChunksWithBufferOf chunkSize h
181toStreamWithBufferOf chunkSize h = AS.concat $ toChunksWithBufferOf chunkSize h
@@ -254,7 +235,7 @@ readDirs = fmap (fromLeft undefined) $ UF.filter isLeft readEither
255-- /Pre-release/
236-- /Pre-release/
256{-# INLINE toStream #-}
237{-# INLINE toStream #-}
257−toStream :: (IsStream t, MonadIO m) => String -> t m String
238+toStream :: MonadIO m => String -> Stream m String
258toStream = S.unfold read
239toStream = S.unfold read
260-- | Read directories as Left and files as Right. Filter out "." and ".."
241-- | Read directories as Left and files as Right. Filter out "." and ".."
@@ -262,8 +243,7 @@ toStream = S.unfold read
263-- /Pre-release/
244-- /Pre-release/
264{-# INLINE toEither #-}
245{-# 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)
267toEither = S.unfold readEither
247toEither = S.unfold readEither
269-- | Read files only.
249-- | Read files only.
@@ -271,7 +251,7 @@ toEither = S.unfold readEither
271-- /Internal/
251-- /Internal/
273{-# INLINE toFiles #-}
253{-# INLINE toFiles #-}
274−toFiles :: (IsStream t, MonadIO m) => String -> t m String
254+toFiles :: MonadIO m => String -> Stream m String
275toFiles = S.unfold readFiles
255toFiles = S.unfold readFiles
277-- | Read directories only.
257-- | Read directories only.
@@ -279,7 +259,7 @@ toFiles = S.unfold readFiles
279-- /Internal/
259-- /Internal/
281{-# INLINE toDirs #-}
261{-# INLINE toDirs #-}
282−toDirs :: (IsStream t, MonadIO m) => String -> t m String
262+toDirs :: MonadIO m => String -> Stream m String
283toDirs = S.unfold readDirs
263toDirs = S.unfold readDirs