on master help sign in
rename Handle readArrays* APIs to toStreamArrays*
commitbf5e153bf5cbbd6b619e3972fa5fc35334218a92 authorHarendra Kumar <harendra.kumar@gmail.com> dateMon 30 Sep 2019, 02:15 (7 years ago) parent8dadcad
7 files changed+51−52
examples/FileIOExamples.hs+3−3 examples/FromFileClient.hs+1−1 examples/HandleIO.hs+3−3 src/Streamly/Benchmark/FileIO/Array.hs+11−11 src/Streamly/Benchmark/FileIO/Stream.hs+2−2 src/Streamly/Internal/FileSystem/File.hs+14−14 src/Streamly/Internal/FileSystem/Handle.hs+17−18
examples/FileIOExamples.hs+3−3
@@ -8,13 +8,13 @@ import Data.Char (ord)
88import System.Environment (getArgs)
99
1010cat :: FilePath -> IO ()
11−cat src = File.writeArrays "/dev/stdout" $ File.readArraysOf (256*1024) src
11+cat src = File.writeArrays "/dev/stdout" $ File.toStreamArraysOf (256*1024) src
1212
1313cp :: FilePath -> FilePath -> IO ()
14−cp src dst = File.writeArrays dst $ File.readArraysOf (256*1024) src
14+cp src dst = File.writeArrays dst $ File.toStreamArraysOf (256*1024) src
1515
1616append :: FilePath -> FilePath -> IO ()
17−append src dst = File.appendArrays dst $ File.readArraysOf (256*1024) src
17+append src dst = File.appendArrays dst $ File.toStreamArraysOf (256*1024) src
1818
1919ord' :: Num a => Char -> a
2020ord' = (fromIntegral . ord)
examples/FromFileClient.hs+1−1
@@ -17,5 +17,5 @@ main =
1717 let sendFile file =
1818 withFile file ReadMode $ \src ->
1919 S.fold (Client.writeArrays (127, 0, 0, 1) 8090)
20− $ IFH.readArrays src
20+ $ IFH.toStreamArrays src
2121 in getArgs >>= S.drain . parallely . S.mapM sendFile . S.fromList
examples/HandleIO.hs+3−3
@@ -13,12 +13,12 @@ import System.Environment (getArgs)
1313import System.IO (IOMode(..), hSeek, SeekMode(..))
1414
1515cat :: FH.Handle -> IO ()
16−cat src = S.fold (IFH.writeArrays FH.stdout) $ IFH.readArraysOf (256*1024) src
16+cat src = S.fold (IFH.writeArrays FH.stdout) $ IFH.toStreamArraysOf (256*1024) src
1717-- byte stream version
1818-- cat src = S.fold (FH.write FH.stdout) $ FH.read src
1919
2020cp :: FH.Handle -> FH.Handle -> IO ()
21−cp src dst = S.fold (IFH.writeArrays dst) $ IFH.readArraysOf (256*1024) src
21+cp src dst = S.fold (IFH.writeArrays dst) $ IFH.toStreamArraysOf (256*1024) src
2222-- byte stream version
2323-- cp src dst = S.fold (FH.write dst) $ FH.read src
2424
@@ -28,7 +28,7 @@ ord' = (fromIntegral . ord)
2828wcl :: FH.Handle -> IO ()
2929wcl src = print =<< (S.length
3030 $ AS.splitOn 10
31− $ IFH.readArrays src)
31+ $ IFH.toStreamArrays src)
3232{-
3333-- Char stream version
3434wcl src = print =<< (S.length
src/Streamly/Benchmark/FileIO/Array.hs+11−11
@@ -59,7 +59,7 @@ import Test.Inspection
5959{-# INLINE last #-}
6060last :: Handle -> IO (Maybe Word8)
6161last inh = do
62− let s = IFH.readArrays inh
62+ let s = IFH.toStreamArrays inh
6363 larr <- S.last s
6464 return $ case larr of
6565 Nothing -> Nothing
@@ -74,7 +74,7 @@ inspect $ 'last `hasNoType` ''Step
7474{-# INLINE countBytes #-}
7575countBytes :: Handle -> IO Int
7676countBytes inh =
77− let s = IFH.readArrays inh
77+ let s = IFH.toStreamArrays inh
7878 in S.sum (S.map A.length s)
7979
8080#ifdef INSPECTION
@@ -85,7 +85,7 @@ inspect $ 'countBytes `hasNoType` ''Step
8585-- | Count the number of lines in a file.
8686{-# INLINE countLines #-}
8787countLines :: Handle -> IO Int
88−countLines = S.length . AS.splitOnSuffix 10 . IFH.readArrays
88+countLines = S.length . AS.splitOnSuffix 10 . IFH.toStreamArrays
8989
9090#ifdef INSPECTION
9191inspect $ hasNoTypeClasses 'countLines
@@ -96,7 +96,7 @@ inspect $ 'countLines `hasNoType` ''Step
9696-- | Count the number of lines in a file.
9797{-# INLINE countWords #-}
9898countWords :: Handle -> IO Int
99−countWords = S.length . AS.splitOn 32 . IFH.readArrays
99+countWords = S.length . AS.splitOn 32 . IFH.toStreamArrays
100100
101101#ifdef INSPECTION
102102inspect $ hasNoTypeClasses 'countWords
@@ -108,7 +108,7 @@ inspect $ 'countWords `hasNoType` ''Step
108108sumBytes :: Handle -> IO Word8
109109sumBytes inh = do
110110 let foldlArr' f z = runIdentity . S.foldl' f z . IA.toStream
111− let s = IFH.readArrays inh
111+ let s = IFH.toStreamArrays inh
112112 S.foldl' (\acc arr -> acc + foldlArr' (+) 0 arr) 0 s
113113
114114#ifdef INSPECTION
@@ -120,7 +120,7 @@ inspect $ 'sumBytes `hasNoType` ''Step
120120{-# INLINE cat #-}
121121cat :: Handle -> Handle -> IO ()
122122cat devNull inh =
123− S.fold (IFH.writeArrays devNull) $ IFH.readArraysOf (256*1024) inh
123+ S.fold (IFH.writeArrays devNull) $ IFH.toStreamArraysOf (256*1024) inh
124124
125125#ifdef INSPECTION
126126inspect $ hasNoTypeClasses 'cat
@@ -131,7 +131,7 @@ inspect $ 'cat `hasNoType` ''Step
131131{-# INLINE copy #-}
132132copy :: Handle -> Handle -> IO ()
133133copy inh outh =
134− let s = IFH.readArrays inh
134+ let s = IFH.toStreamArrays inh
135135 in S.fold (IFH.writeArrays outh) s
136136
137137#ifdef INSPECTION
@@ -146,7 +146,7 @@ linesUnlinesCopy inh outh =
146146 S.fold (IFH.writeArraysInChunksOf (1024*1024) outh)
147147 $ Internal.insertAfterEach (return $ A.fromList [10])
148148 $ AS.splitOnSuffix 10
149− $ IFH.readArraysOf (1024*1024) inh
149+ $ IFH.toStreamArraysOf (1024*1024) inh
150150
151151#ifdef INSPECTION
152152inspect $ hasNoTypeClassesExcept 'linesUnlinesCopy [''Storable]
@@ -161,7 +161,7 @@ wordsUnwordsCopy inh outh =
161161 $ S.intersperse (A.fromList [32])
162162 -- XXX use a word splitting combinator
163163 $ AS.splitOn 32
164− $ IFH.readArraysOf (1024*1024) inh
164+ $ IFH.toStreamArraysOf (1024*1024) inh
165165
166166#ifdef INSPECTION
167167inspect $ hasNoTypeClassesExcept 'wordsUnwordsCopy [''Storable]
@@ -173,7 +173,7 @@ decodeUtf8Lenient :: Handle -> IO ()
173173decodeUtf8Lenient inh =
174174 S.drain
175175 $ SS.decodeUtf8ArraysLenient
176− $ IFH.readArraysOf (1024*1024) inh
176+ $ IFH.toStreamArraysOf (1024*1024) inh
177177
178178#ifdef INSPECTION
179179inspect $ hasNoTypeClasses 'decodeUtf8Lenient
@@ -189,7 +189,7 @@ copyCodecUtf8Lenient inh outh =
189189 S.fold (FH.write outh)
190190 $ SS.encodeUtf8
191191 $ SS.decodeUtf8ArraysLenient
192− $ IFH.readArraysOf (1024*1024) inh
192+ $ IFH.toStreamArraysOf (1024*1024) inh
193193
194194#ifdef INSPECTION
195195inspect $ hasNoTypeClasses 'copyCodecUtf8Lenient
src/Streamly/Benchmark/FileIO/Stream.hs+2−2
@@ -135,7 +135,7 @@ countLinesU inh =
135135 S.length
136136 $ SS.foldLines FL.drain
137137 $ SS.decodeChar8
138− $ S.concatUnfold A.read (IFH.readArrays inh)
138+ $ S.concatUnfold A.read (IFH.toStreamArrays inh)
139139
140140#ifdef INSPECTION
141141inspect $ hasNoTypeClasses 'countLinesU
@@ -456,7 +456,7 @@ splitOnSeqUtf8 :: String -> Handle -> IO Int
456456splitOnSeqUtf8 str inh =
457457 (S.length $ IP.splitOnSeq (A.fromList str) FL.drain
458458 $ SS.decodeUtf8ArraysLenient
459− $ IFH.readArrays inh) -- >>= print
459+ $ IFH.toStreamArrays inh) -- >>= print
460460
461461-- | Split on suffix sequence.
462462{-# INLINE splitOnSuffixSeq #-}
src/Streamly/Internal/FileSystem/File.hs+14−14
@@ -63,9 +63,9 @@ module Streamly.Internal.FileSystem.File
6363 -- -- * Array Read
6464 -- , readArrayOf
6565
66− , readArraysOf
67− -- , readArraysOf
68− , readArrays
66+ , toStreamArraysOf
67+ -- , toStreamArraysOf
68+ , toStreamArrays
6969
7070 -- ** Write To File
7171 , write
@@ -182,27 +182,27 @@ appendArray file arr = SIO.withFile file AppendMode (\h -> FH.writeArray h arr)
182182-- Stream of Arrays IO
183183-------------------------------------------------------------------------------
184184
185−-- | @readArraysOf size file@ reads a stream of arrays from file @file@.
185+-- | @toStreamArraysOf size file@ reads a stream of arrays from file @file@.
186186-- The maximum size of a single array is specified by @size@. The actual size
187187-- read may be less than or equal to @size@.
188−{-# INLINABLE readArraysOf #-}
189−readArraysOf :: (IsStream t, MonadCatch m, MonadIO m)
188+{-# INLINABLE toStreamArraysOf #-}
189+toStreamArraysOf :: (IsStream t, MonadCatch m, MonadIO m)
190190 => Int -> FilePath -> t m (Array Word8)
191−readArraysOf size file = withFile file ReadMode (FH.readArraysOf size)
191+toStreamArraysOf size file = withFile file ReadMode (FH.toStreamArraysOf size)
192192
193193-- XXX read 'Array a' instead of Word8
194194--
195−-- | @readArrays file@ reads a stream of arrays from file @file@.
195+-- | @toStreamArrays file@ reads a stream of arrays from file @file@.
196196-- The maximum size of a single array is limited to @defaultChunkSize@. The
197197-- actual size read may be less than @defaultChunkSize@.
198198--
199−-- > readArrays = readArraysOf defaultChunkSize
199+-- > toStreamArrays = toStreamArraysOf defaultChunkSize
200200--
201201-- @since 0.7.0
202−{-# INLINE readArrays #-}
203−readArrays :: (IsStream t, MonadCatch m, MonadIO m)
202+{-# INLINE toStreamArrays #-}
203+toStreamArrays :: (IsStream t, MonadCatch m, MonadIO m)
204204 => FilePath -> t m (Array Word8)
205−readArrays = readArraysOf defaultChunkSize
205+toStreamArrays = toStreamArraysOf defaultChunkSize
206206
207207-------------------------------------------------------------------------------
208208-- Read File to Stream
@@ -219,7 +219,7 @@ readArrays = readArraysOf defaultChunkSize
219219--
220220{-# INLINE readInChunksOf #-}
221221readInChunksOf :: (IsStream t, MonadIO m) => Int -> Handle -> t m Word8
222−readInChunksOf chunkSize h = A.flattenArrays $ readArraysOf chunkSize h
222+readInChunksOf chunkSize h = A.flattenArrays $ toStreamArraysOf chunkSize h
223223-}
224224
225225-- TODO
@@ -233,7 +233,7 @@ readInChunksOf chunkSize h = A.flattenArrays $ readArraysOf chunkSize h
233233-- @since 0.7.0
234234{-# INLINE read #-}
235235read :: (IsStream t, MonadCatch m, MonadIO m) => FilePath -> t m Word8
236−read file = AS.concat $ withFile file ReadMode FH.readArrays
236+read file = AS.concat $ withFile file ReadMode FH.toStreamArrays
237237
238238{-
239239-- | Generate a stream of elements of the given type from a file 'Handle'. The
src/Streamly/Internal/FileSystem/Handle.hs+17−18
@@ -28,9 +28,8 @@ module Streamly.Internal.FileSystem.Handle
2828 -- , readArrayUpto
2929 -- , readArrayOf
3030
31− , readArraysOf
32− -- , readArraysOf
33− , readArrays
31+ , toStreamArraysOf
32+ , toStreamArrays
3433
3534 -- ** Write to Handle
3635 -- Byte stream write (Folds)
@@ -139,13 +138,13 @@ readArrayUpto size h = do
139138-- Stream of Arrays IO
140139-------------------------------------------------------------------------------
141140
142−-- | @readArraysOf size h@ reads a stream of arrays from file handle @h@.
141+-- | @toStreamArraysOf size h@ reads a stream of arrays from file handle @h@.
143142-- The maximum size of a single array is specified by @size@. The actual size
144143-- read may be less than or equal to @size@.
145−{-# INLINABLE _readArraysOf #-}
146−_readArraysOf :: (IsStream t, MonadIO m)
144+{-# INLINABLE _toStreamArraysOf #-}
145+_toStreamArraysOf :: (IsStream t, MonadIO m)
147146 => Int -> Handle -> t m (Array Word8)
148−_readArraysOf size h = go
147+_toStreamArraysOf size h = go
149148 where
150149 -- XXX use cons/nil instead
151150 go = mkStream $ \_ yld _ stp -> do
@@ -154,14 +153,14 @@ _readArraysOf size h = go
154153 then stp
155154 else yld arr go
156155
157−-- | @readArraysOf size handle@ reads a stream of arrays from the file
156+-- | @toStreamArraysOf size handle@ reads a stream of arrays from the file
158157-- handle @handle@. The maximum size of a single array is limited to @size@.
159158-- The actual size read may be less than or equal to @size@.
160159--
161160-- @since 0.7.0
162−{-# INLINE_NORMAL readArraysOf #-}
163−readArraysOf :: (IsStream t, MonadIO m) => Int -> Handle -> t m (Array Word8)
164−readArraysOf size h = D.fromStreamD (D.Stream step ())
161+{-# INLINE_NORMAL toStreamArraysOf #-}
162+toStreamArraysOf :: (IsStream t, MonadIO m) => Int -> Handle -> t m (Array Word8)
163+toStreamArraysOf size h = D.fromStreamD (D.Stream step ())
165164 where
166165 {-# INLINE_LATE step #-}
167166 step _ _ = do
@@ -173,17 +172,17 @@ readArraysOf size h = D.fromStreamD (D.Stream step ())
173172
174173-- XXX read 'Array a' instead of Word8
175174--
176−-- | @readArrays handle@ reads a stream of arrays from the specified file
175+-- | @toStreamArrays handle@ reads a stream of arrays from the specified file
177176-- handle. The maximum size of a single array is limited to
178177-- @defaultChunkSize@. The actual size read may be less than or equal to
179178-- @defaultChunkSize@.
180179--
181−-- > readArrays = readArraysOf defaultChunkSize
180+-- > toStreamArrays = toStreamArraysOf defaultChunkSize
182181--
183182-- @since 0.7.0
184−{-# INLINE readArrays #-}
185−readArrays :: (IsStream t, MonadIO m) => Handle -> t m (Array Word8)
186−readArrays = readArraysOf defaultChunkSize
183+{-# INLINE toStreamArrays #-}
184+toStreamArrays :: (IsStream t, MonadIO m) => Handle -> t m (Array Word8)
185+toStreamArrays = toStreamArraysOf defaultChunkSize
187186
188187-------------------------------------------------------------------------------
189188-- Read File to Stream
@@ -199,7 +198,7 @@ readArrays = readArraysOf defaultChunkSize
199198-- @since 0.7.0
200199{-# INLINE readInChunksOf #-}
201200readInChunksOf :: (IsStream t, MonadIO m) => Int -> Handle -> t m Word8
202−readInChunksOf chunkSize h = AS.concat $ readArraysOf chunkSize h
201+readInChunksOf chunkSize h = AS.concat $ toStreamArraysOf chunkSize h
203202
204203-- TODO
205204-- Generate a stream of elements of the given type from a file 'Handle'.
@@ -211,7 +210,7 @@ readInChunksOf chunkSize h = AS.concat $ readArraysOf chunkSize h
211210-- @since 0.7.0
212211{-# INLINE read #-}
213212read :: (IsStream t, MonadIO m) => Handle -> t m Word8
214−read = AS.concat . readArrays
213+read = AS.concat . toStreamArrays
215214
216215-------------------------------------------------------------------------------
217216-- Writing