@@ -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{-