on master help sign in
rename Handle readArrays* APIs to toStreamArrays*
bf5e153Harendra Kumar
examples/FileIOExamples.hs+3−3
@@ -8,13 +8,13 @@ import Data.Char (ord)
8import System.Environment (getArgs)
8import System.Environment (getArgs)
9
9
10cat :: FilePath -> IO ()
10cat :: 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
12
12
13cp :: FilePath -> FilePath -> IO ()
13cp :: 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
15
15
16append :: FilePath -> FilePath -> IO ()
16append :: 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
18
18
19ord' :: Num a => Char -> a
19ord' :: Num a => Char -> a
20ord' = (fromIntegral . ord)
20ord' = (fromIntegral . ord)
examples/FromFileClient.hs+1−1
@@ -17,5 +17,5 @@ main =
17 let sendFile file =
17 let sendFile file =
18 withFile file ReadMode $ \src ->
18 withFile file ReadMode $ \src ->
19 S.fold (Client.writeArrays (127, 0, 0, 1) 8090)
19 S.fold (Client.writeArrays (127, 0, 0, 1) 8090)
20− $ IFH.readArrays src
20+ $ IFH.toStreamArrays src
21 in getArgs >>= S.drain . parallely . S.mapM sendFile . S.fromList
21 in getArgs >>= S.drain . parallely . S.mapM sendFile . S.fromList
examples/HandleIO.hs+3−3
@@ -13,12 +13,12 @@ import System.Environment (getArgs)
13import System.IO (IOMode(..), hSeek, SeekMode(..))
13import System.IO (IOMode(..), hSeek, SeekMode(..))
14
14
15cat :: FH.Handle -> IO ()
15cat :: 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
17-- byte stream version
17-- byte stream version
18-- cat src = S.fold (FH.write FH.stdout) $ FH.read src
18-- cat src = S.fold (FH.write FH.stdout) $ FH.read src
19
19
20cp :: FH.Handle -> FH.Handle -> IO ()
20cp :: 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
22-- byte stream version
22-- byte stream version
23-- cp src dst = S.fold (FH.write dst) $ FH.read src
23-- cp src dst = S.fold (FH.write dst) $ FH.read src
24
24
@@ -28,7 +28,7 @@ ord' = (fromIntegral . ord)
28wcl :: FH.Handle -> IO ()
28wcl :: FH.Handle -> IO ()
29wcl src = print =<< (S.length
29wcl src = print =<< (S.length
30 $ AS.splitOn 10
30 $ AS.splitOn 10
31− $ IFH.readArrays src)
31+ $ IFH.toStreamArrays src)
32{-
32{-
33-- Char stream version
33-- Char stream version
34wcl src = print =<< (S.length
34wcl src = print =<< (S.length
src/Streamly/Benchmark/FileIO/Array.hs+11−11
@@ -59,7 +59,7 @@ import Test.Inspection
59{-# INLINE last #-}
59{-# INLINE last #-}
60last :: Handle -> IO (Maybe Word8)
60last :: Handle -> IO (Maybe Word8)
61last inh = do
61last inh = do
62− let s = IFH.readArrays inh
62+ let s = IFH.toStreamArrays inh
63 larr <- S.last s
63 larr <- S.last s
64 return $ case larr of
64 return $ case larr of
65 Nothing -> Nothing
65 Nothing -> Nothing
@@ -74,7 +74,7 @@ inspect $ 'last `hasNoType` ''Step
74{-# INLINE countBytes #-}
74{-# INLINE countBytes #-}
75countBytes :: Handle -> IO Int
75countBytes :: Handle -> IO Int
76countBytes inh =
76countBytes inh =
77− let s = IFH.readArrays inh
77+ let s = IFH.toStreamArrays inh
78 in S.sum (S.map A.length s)
78 in S.sum (S.map A.length s)
79
79
80#ifdef INSPECTION
80#ifdef INSPECTION
@@ -85,7 +85,7 @@ inspect $ 'countBytes `hasNoType` ''Step
85-- | Count the number of lines in a file.
85-- | Count the number of lines in a file.
86{-# INLINE countLines #-}
86{-# INLINE countLines #-}
87countLines :: Handle -> IO Int
87countLines :: Handle -> IO Int
88−countLines = S.length . AS.splitOnSuffix 10 . IFH.readArrays
88+countLines = S.length . AS.splitOnSuffix 10 . IFH.toStreamArrays
89
89
90#ifdef INSPECTION
90#ifdef INSPECTION
91inspect $ hasNoTypeClasses 'countLines
91inspect $ hasNoTypeClasses 'countLines
@@ -96,7 +96,7 @@ inspect $ 'countLines `hasNoType` ''Step
96-- | Count the number of lines in a file.
96-- | Count the number of lines in a file.
97{-# INLINE countWords #-}
97{-# INLINE countWords #-}
98countWords :: Handle -> IO Int
98countWords :: Handle -> IO Int
99−countWords = S.length . AS.splitOn 32 . IFH.readArrays
99+countWords = S.length . AS.splitOn 32 . IFH.toStreamArrays
100
100
101#ifdef INSPECTION
101#ifdef INSPECTION
102inspect $ hasNoTypeClasses 'countWords
102inspect $ hasNoTypeClasses 'countWords
@@ -108,7 +108,7 @@ inspect $ 'countWords `hasNoType` ''Step
108sumBytes :: Handle -> IO Word8
108sumBytes :: Handle -> IO Word8
109sumBytes inh = do
109sumBytes inh = do
110 let foldlArr' f z = runIdentity . S.foldl' f z . IA.toStream
110 let foldlArr' f z = runIdentity . S.foldl' f z . IA.toStream
111− let s = IFH.readArrays inh
111+ let s = IFH.toStreamArrays inh
112 S.foldl' (\acc arr -> acc + foldlArr' (+) 0 arr) 0 s
112 S.foldl' (\acc arr -> acc + foldlArr' (+) 0 arr) 0 s
113
113
114#ifdef INSPECTION
114#ifdef INSPECTION
@@ -120,7 +120,7 @@ inspect $ 'sumBytes `hasNoType` ''Step
120{-# INLINE cat #-}
120{-# INLINE cat #-}
121cat :: Handle -> Handle -> IO ()
121cat :: Handle -> Handle -> IO ()
122cat devNull inh =
122cat devNull inh =
123− S.fold (IFH.writeArrays devNull) $ IFH.readArraysOf (256*1024) inh
123+ S.fold (IFH.writeArrays devNull) $ IFH.toStreamArraysOf (256*1024) inh
124
124
125#ifdef INSPECTION
125#ifdef INSPECTION
126inspect $ hasNoTypeClasses 'cat
126inspect $ hasNoTypeClasses 'cat
@@ -131,7 +131,7 @@ inspect $ 'cat `hasNoType` ''Step
131{-# INLINE copy #-}
131{-# INLINE copy #-}
132copy :: Handle -> Handle -> IO ()
132copy :: Handle -> Handle -> IO ()
133copy inh outh =
133copy inh outh =
134− let s = IFH.readArrays inh
134+ let s = IFH.toStreamArrays inh
135 in S.fold (IFH.writeArrays outh) s
135 in S.fold (IFH.writeArrays outh) s
136
136
137#ifdef INSPECTION
137#ifdef INSPECTION
@@ -146,7 +146,7 @@ linesUnlinesCopy inh outh =
146 S.fold (IFH.writeArraysInChunksOf (1024*1024) outh)
146 S.fold (IFH.writeArraysInChunksOf (1024*1024) outh)
147 $ Internal.insertAfterEach (return $ A.fromList [10])
147 $ Internal.insertAfterEach (return $ A.fromList [10])
148 $ AS.splitOnSuffix 10
148 $ AS.splitOnSuffix 10
149− $ IFH.readArraysOf (1024*1024) inh
149+ $ IFH.toStreamArraysOf (1024*1024) inh
150
150
151#ifdef INSPECTION
151#ifdef INSPECTION
152inspect $ hasNoTypeClassesExcept 'linesUnlinesCopy [''Storable]
152inspect $ hasNoTypeClassesExcept 'linesUnlinesCopy [''Storable]
@@ -161,7 +161,7 @@ wordsUnwordsCopy inh outh =
161 $ S.intersperse (A.fromList [32])
161 $ S.intersperse (A.fromList [32])
162 -- XXX use a word splitting combinator
162 -- XXX use a word splitting combinator
163 $ AS.splitOn 32
163 $ AS.splitOn 32
164− $ IFH.readArraysOf (1024*1024) inh
164+ $ IFH.toStreamArraysOf (1024*1024) inh
165
165
166#ifdef INSPECTION
166#ifdef INSPECTION
167inspect $ hasNoTypeClassesExcept 'wordsUnwordsCopy [''Storable]
167inspect $ hasNoTypeClassesExcept 'wordsUnwordsCopy [''Storable]
@@ -173,7 +173,7 @@ decodeUtf8Lenient :: Handle -> IO ()
173decodeUtf8Lenient inh =
173decodeUtf8Lenient inh =
174 S.drain
174 S.drain
175 $ SS.decodeUtf8ArraysLenient
175 $ SS.decodeUtf8ArraysLenient
176− $ IFH.readArraysOf (1024*1024) inh
176+ $ IFH.toStreamArraysOf (1024*1024) inh
177
177
178#ifdef INSPECTION
178#ifdef INSPECTION
179inspect $ hasNoTypeClasses 'decodeUtf8Lenient
179inspect $ hasNoTypeClasses 'decodeUtf8Lenient
@@ -189,7 +189,7 @@ copyCodecUtf8Lenient inh outh =
189 S.fold (FH.write outh)
189 S.fold (FH.write outh)
190 $ SS.encodeUtf8
190 $ SS.encodeUtf8
191 $ SS.decodeUtf8ArraysLenient
191 $ SS.decodeUtf8ArraysLenient
192− $ IFH.readArraysOf (1024*1024) inh
192+ $ IFH.toStreamArraysOf (1024*1024) inh
193
193
194#ifdef INSPECTION
194#ifdef INSPECTION
195inspect $ hasNoTypeClasses 'copyCodecUtf8Lenient
195inspect $ hasNoTypeClasses 'copyCodecUtf8Lenient
src/Streamly/Benchmark/FileIO/Stream.hs+2−2
@@ -135,7 +135,7 @@ countLinesU inh =
135 S.length
135 S.length
136 $ SS.foldLines FL.drain
136 $ SS.foldLines FL.drain
137 $ SS.decodeChar8
137 $ SS.decodeChar8
138− $ S.concatUnfold A.read (IFH.readArrays inh)
138+ $ S.concatUnfold A.read (IFH.toStreamArrays inh)
139
139
140#ifdef INSPECTION
140#ifdef INSPECTION
141inspect $ hasNoTypeClasses 'countLinesU
141inspect $ hasNoTypeClasses 'countLinesU
@@ -456,7 +456,7 @@ splitOnSeqUtf8 :: String -> Handle -> IO Int
456splitOnSeqUtf8 str inh =
456splitOnSeqUtf8 str inh =
457 (S.length $ IP.splitOnSeq (A.fromList str) FL.drain
457 (S.length $ IP.splitOnSeq (A.fromList str) FL.drain
458 $ SS.decodeUtf8ArraysLenient
458 $ SS.decodeUtf8ArraysLenient
459− $ IFH.readArrays inh) -- >>= print
459+ $ IFH.toStreamArrays inh) -- >>= print
460
460
461-- | Split on suffix sequence.
461-- | Split on suffix sequence.
462{-# INLINE splitOnSuffixSeq #-}
462{-# INLINE splitOnSuffixSeq #-}
src/Streamly/Internal/FileSystem/File.hs+14−14
@@ -63,9 +63,9 @@ module Streamly.Internal.FileSystem.File
63 -- -- * Array Read
63 -- -- * Array Read
64 -- , readArrayOf
64 -- , readArrayOf
65
65
66− , readArraysOf
66+ , toStreamArraysOf
67− -- , readArraysOf
67+ -- , toStreamArraysOf
68− , readArrays
68+ , toStreamArrays
69
69
70 -- ** Write To File
70 -- ** Write To File
71 , write
71 , write
@@ -182,27 +182,27 @@ appendArray file arr = SIO.withFile file AppendMode (\h -> FH.writeArray h arr)
182-- Stream of Arrays IO
182-- Stream of Arrays IO
183-------------------------------------------------------------------------------
183-------------------------------------------------------------------------------
184
184
185−-- | @readArraysOf size file@ reads a stream of arrays from file @file@.
185+-- | @toStreamArraysOf size file@ reads a stream of arrays from file @file@.
186-- The maximum size of a single array is specified by @size@. The actual size
186-- The maximum size of a single array is specified by @size@. The actual size
187-- read may be less than or equal to @size@.
187-- read may be less than or equal to @size@.
188−{-# INLINABLE readArraysOf #-}
188+{-# INLINABLE toStreamArraysOf #-}
189−readArraysOf :: (IsStream t, MonadCatch m, MonadIO m)
189+toStreamArraysOf :: (IsStream t, MonadCatch m, MonadIO m)
190 => Int -> FilePath -> t m (Array Word8)
190 => 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)
192
192
193-- XXX read 'Array a' instead of Word8
193-- XXX read 'Array a' instead of Word8
194--
194--
195−-- | @readArrays file@ reads a stream of arrays from file @file@.
195+-- | @toStreamArrays file@ reads a stream of arrays from file @file@.
196-- The maximum size of a single array is limited to @defaultChunkSize@. The
196-- The maximum size of a single array is limited to @defaultChunkSize@. The
197-- actual size read may be less than @defaultChunkSize@.
197-- actual size read may be less than @defaultChunkSize@.
198--
198--
199−-- > readArrays = readArraysOf defaultChunkSize
199+-- > toStreamArrays = toStreamArraysOf defaultChunkSize
200--
200--
201-- @since 0.7.0
201-- @since 0.7.0
202−{-# INLINE readArrays #-}
202+{-# INLINE toStreamArrays #-}
203−readArrays :: (IsStream t, MonadCatch m, MonadIO m)
203+toStreamArrays :: (IsStream t, MonadCatch m, MonadIO m)
204 => FilePath -> t m (Array Word8)
204 => FilePath -> t m (Array Word8)
205−readArrays = readArraysOf defaultChunkSize
205+toStreamArrays = toStreamArraysOf defaultChunkSize
206
206
207-------------------------------------------------------------------------------
207-------------------------------------------------------------------------------
208-- Read File to Stream
208-- Read File to Stream
@@ -219,7 +219,7 @@ readArrays = readArraysOf defaultChunkSize
219--
219--
220{-# INLINE readInChunksOf #-}
220{-# INLINE readInChunksOf #-}
221readInChunksOf :: (IsStream t, MonadIO m) => Int -> Handle -> t m Word8
221readInChunksOf :: (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
223-}
223-}
224
224
225-- TODO
225-- TODO
@@ -233,7 +233,7 @@ readInChunksOf chunkSize h = A.flattenArrays $ readArraysOf chunkSize h
233-- @since 0.7.0
233-- @since 0.7.0
234{-# INLINE read #-}
234{-# INLINE read #-}
235read :: (IsStream t, MonadCatch m, MonadIO m) => FilePath -> t m Word8
235read :: (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
237
237
238{-
238{-
239-- | Generate a stream of elements of the given type from a file 'Handle'. The
239-- | 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
28 -- , readArrayUpto
28 -- , readArrayUpto
29 -- , readArrayOf
29 -- , readArrayOf
30
30
31− , readArraysOf
31+ , toStreamArraysOf
32− -- , readArraysOf
32+ , toStreamArrays
33− , readArrays
34
33
35 -- ** Write to Handle
34 -- ** Write to Handle
36 -- Byte stream write (Folds)
35 -- Byte stream write (Folds)
@@ -139,13 +138,13 @@ readArrayUpto size h = do
139-- Stream of Arrays IO
138-- Stream of Arrays IO
140-------------------------------------------------------------------------------
139-------------------------------------------------------------------------------
141
140
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@.
143-- The maximum size of a single array is specified by @size@. The actual size
142-- The maximum size of a single array is specified by @size@. The actual size
144-- read may be less than or equal to @size@.
143-- read may be less than or equal to @size@.
145−{-# INLINABLE _readArraysOf #-}
144+{-# INLINABLE _toStreamArraysOf #-}
146−_readArraysOf :: (IsStream t, MonadIO m)
145+_toStreamArraysOf :: (IsStream t, MonadIO m)
147 => Int -> Handle -> t m (Array Word8)
146 => Int -> Handle -> t m (Array Word8)
148−_readArraysOf size h = go
147+_toStreamArraysOf size h = go
149 where
148 where
150 -- XXX use cons/nil instead
149 -- XXX use cons/nil instead
151 go = mkStream $ \_ yld _ stp -> do
150 go = mkStream $ \_ yld _ stp -> do
@@ -154,14 +153,14 @@ _readArraysOf size h = go
154 then stp
153 then stp
155 else yld arr go
154 else yld arr go
156
155
157−-- | @readArraysOf size handle@ reads a stream of arrays from the file
156+-- | @toStreamArraysOf size handle@ reads a stream of arrays from the file
158-- handle @handle@. The maximum size of a single array is limited to @size@.
157-- handle @handle@. The maximum size of a single array is limited to @size@.
159-- The actual size read may be less than or equal to @size@.
158-- The actual size read may be less than or equal to @size@.
160--
159--
161-- @since 0.7.0
160-- @since 0.7.0
162−{-# INLINE_NORMAL readArraysOf #-}
161+{-# INLINE_NORMAL toStreamArraysOf #-}
163−readArraysOf :: (IsStream t, MonadIO m) => Int -> Handle -> t m (Array Word8)
162+toStreamArraysOf :: (IsStream t, MonadIO m) => Int -> Handle -> t m (Array Word8)
164−readArraysOf size h = D.fromStreamD (D.Stream step ())
163+toStreamArraysOf size h = D.fromStreamD (D.Stream step ())
165 where
164 where
166 {-# INLINE_LATE step #-}
165 {-# INLINE_LATE step #-}
167 step _ _ = do
166 step _ _ = do
@@ -173,17 +172,17 @@ readArraysOf size h = D.fromStreamD (D.Stream step ())
173
172
174-- XXX read 'Array a' instead of Word8
173-- XXX read 'Array a' instead of Word8
175--
174--
176−-- | @readArrays handle@ reads a stream of arrays from the specified file
175+-- | @toStreamArrays handle@ reads a stream of arrays from the specified file
177-- handle. The maximum size of a single array is limited to
176-- handle. The maximum size of a single array is limited to
178-- @defaultChunkSize@. The actual size read may be less than or equal to
177-- @defaultChunkSize@. The actual size read may be less than or equal to
179-- @defaultChunkSize@.
178-- @defaultChunkSize@.
180--
179--
181−-- > readArrays = readArraysOf defaultChunkSize
180+-- > toStreamArrays = toStreamArraysOf defaultChunkSize
182--
181--
183-- @since 0.7.0
182-- @since 0.7.0
184−{-# INLINE readArrays #-}
183+{-# INLINE toStreamArrays #-}
185−readArrays :: (IsStream t, MonadIO m) => Handle -> t m (Array Word8)
184+toStreamArrays :: (IsStream t, MonadIO m) => Handle -> t m (Array Word8)
186−readArrays = readArraysOf defaultChunkSize
185+toStreamArrays = toStreamArraysOf defaultChunkSize
187
186
188-------------------------------------------------------------------------------
187-------------------------------------------------------------------------------
189-- Read File to Stream
188-- Read File to Stream
@@ -199,7 +198,7 @@ readArrays = readArraysOf defaultChunkSize
199-- @since 0.7.0
198-- @since 0.7.0
200{-# INLINE readInChunksOf #-}
199{-# INLINE readInChunksOf #-}
201readInChunksOf :: (IsStream t, MonadIO m) => Int -> Handle -> t m Word8
200readInChunksOf :: (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
203
202
204-- TODO
203-- TODO
205-- Generate a stream of elements of the given type from a file 'Handle'.
204-- 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
211-- @since 0.7.0
210-- @since 0.7.0
212{-# INLINE read #-}
211{-# INLINE read #-}
213read :: (IsStream t, MonadIO m) => Handle -> t m Word8
212read :: (IsStream t, MonadIO m) => Handle -> t m Word8
214−read = AS.concat . readArrays
213+read = AS.concat . toStreamArrays
215
214
216-------------------------------------------------------------------------------
215-------------------------------------------------------------------------------
217-- Writing
216-- Writing