on master help sign in
Merge pull request #249 from composewell/misc-refactorings
72177d0Harendra Kumar
benchmark/FileIO.hs+2−2
@@ -117,7 +117,7 @@ main = do
117 S.foldl' (\acc arr -> acc + foldlArr' (+) 0 arr) 0 s
117 S.foldl' (\acc arr -> acc + foldlArr' (+) 0 arr) 0 s
118 , mkBench "cat" href $ do
118 , mkBench "cat" href $ do
119 Handles inh _ <- readIORef href
119 Handles inh _ <- readIORef href
120− FH.writeArrays devNull $ FH.readArraysOfUpto (256*1024) inh
120+ FH.writeArrays devNull $ FH.readArraysOf (256*1024) inh
121 ]
121 ]
122 , bgroup "readStream"
122 , bgroup "readStream"
123 [ mkBench "last" href $ do
123 [ mkBench "last" href $ do
@@ -198,7 +198,7 @@ main = do
198 FH.writeArraysPackedUpto (1024*1024) outh
198 FH.writeArraysPackedUpto (1024*1024) outh
199 $ S.insertAfterEach (return $ A.fromList [10])
199 $ S.insertAfterEach (return $ A.fromList [10])
200 $ AS.splitOn 10
200 $ AS.splitOn 10
201− $ FH.readArraysOfUpto (1024*1024) inh
201+ $ FH.readArraysOf (1024*1024) inh
202 -}
202 -}
203 , mkBench "words-unwords" href $ do
203 , mkBench "words-unwords" href $ do
204 Handles inh outh <- readIORef href
204 Handles inh outh <- readIORef href
examples/FileIOExamples.hs+3−3
@@ -7,13 +7,13 @@ import Data.Char (ord)
7import System.Environment (getArgs)
7import System.Environment (getArgs)
8
8
9cat :: FilePath -> IO ()
9cat :: FilePath -> IO ()
10−cat src = File.writeArrays "/dev/stdout" $ File.readArraysOfUpto (256*1024) src
10+cat src = File.writeArrays "/dev/stdout" $ File.readArraysOf (256*1024) src
11
11
12cp :: FilePath -> FilePath -> IO ()
12cp :: FilePath -> FilePath -> IO ()
13−cp src dst = File.writeArrays dst $ File.readArraysOfUpto (256*1024) src
13+cp src dst = File.writeArrays dst $ File.readArraysOf (256*1024) src
14
14
15append :: FilePath -> FilePath -> IO ()
15append :: FilePath -> FilePath -> IO ()
16−append src dst = File.appendArrays dst $ File.readArraysOfUpto (256*1024) src
16+append src dst = File.appendArrays dst $ File.readArraysOf (256*1024) src
17
17
18ord' :: Num a => Char -> a
18ord' :: Num a => Char -> a
19ord' = (fromIntegral . ord)
19ord' = (fromIntegral . ord)
examples/HandleIO.hs+2−2
@@ -12,12 +12,12 @@ import System.Environment (getArgs)
12import System.IO (IOMode(..), hSeek, SeekMode(..))
12import System.IO (IOMode(..), hSeek, SeekMode(..))
13
13
14cat :: FH.Handle -> IO ()
14cat :: FH.Handle -> IO ()
15−cat src = FH.writeArrays FH.stdout $ FH.readArraysOfUpto (256*1024) src
15+cat src = FH.writeArrays FH.stdout $ FH.readArraysOf (256*1024) src
16-- byte stream version
16-- byte stream version
17-- cat src = FH.write FH.stdout $ FH.read src
17-- cat src = FH.write FH.stdout $ FH.read src
18
18
19cp :: FH.Handle -> FH.Handle -> IO ()
19cp :: FH.Handle -> FH.Handle -> IO ()
20−cp src dst = FH.writeArrays dst $ FH.readArraysOfUpto (256*1024) src
20+cp src dst = FH.writeArrays dst $ FH.readArraysOf (256*1024) src
21-- byte stream version
21-- byte stream version
22-- cp src dst = FH.write dst $ FH.read src
22-- cp src dst = FH.write dst $ FH.read src
23
23
src/Streamly/FileSystem/FD.hs+11−11
@@ -75,7 +75,7 @@ module Streamly.FileSystem.FD
75 -- , readUtf8
75 -- , readUtf8
76 -- , readLines
76 -- , readLines
77 -- , readFrames
77 -- , readFrames
78− , readByChunksUpto
78+ , readInChunksOf
79
79
80 -- -- * Array Read
80 -- -- * Array Read
81 -- , readArrayUpto
81 -- , readArrayUpto
@@ -90,7 +90,7 @@ module Streamly.FileSystem.FD
90 -- , writeUtf8
90 -- , writeUtf8
91 -- , writeUtf8Lines
91 -- , writeUtf8Lines
92 -- , writeFrames
92 -- , writeFrames
93− , writeByChunksOf
93+ , writeInChunksOf
94
94
95 -- -- * Array Write
95 -- -- * Array Write
96 -- , writeArray
96 -- , writeArray
@@ -321,13 +321,13 @@ readArrays = readArraysOfUpto defaultChunkSize
321-- read requests at the same time. For serial case we can use async IO. We can
321-- read requests at the same time. For serial case we can use async IO. We can
322-- also control the read throughput in mbps or IOPS.
322-- also control the read throughput in mbps or IOPS.
323
323
324−-- | @readByChunksUpto chunkSize handle@ reads a byte stream from a file handle,
324+-- | @readInChunksOf chunkSize handle@ reads a byte stream from a file handle,
325-- reads are performed in chunks of up to @chunkSize@. The stream ends as soon
325-- reads are performed in chunks of up to @chunkSize@. The stream ends as soon
326-- as EOF is encountered.
326-- as EOF is encountered.
327--
327--
328−{-# INLINE readByChunksUpto #-}
328+{-# INLINE readInChunksOf #-}
329−readByChunksUpto :: (IsStream t, MonadIO m) => Int -> Handle -> t m Word8
329+readInChunksOf :: (IsStream t, MonadIO m) => Int -> Handle -> t m Word8
330−readByChunksUpto chunkSize h = AS.flatten $ readArraysOfUpto chunkSize h
330+readInChunksOf chunkSize h = AS.flatten $ readArraysOfUpto chunkSize h
331
331
332-- TODO
332-- TODO
333-- read :: (IsStream t, MonadIO m, Storable a) => Handle -> t m a
333-- read :: (IsStream t, MonadIO m, Storable a) => Handle -> t m a
@@ -399,11 +399,11 @@ _writevArraysPackedUpto n h xs =
399-- input elements.
399-- input elements.
400--
400--
401-- @since 0.7.0
401-- @since 0.7.0
402−{-# INLINE writeByChunksOf #-}
402+{-# INLINE writeInChunksOf #-}
403−writeByChunksOf :: MonadIO m => Int -> Handle -> SerialT m Word8 -> m ()
403+writeInChunksOf :: MonadIO m => Int -> Handle -> SerialT m Word8 -> m ()
404−writeByChunksOf n h m = writeArrays h $ AS.arraysOf n m
404+writeInChunksOf n h m = writeArrays h $ AS.arraysOf n m
405
405
406−-- > write = 'writeByChunks' A.defaultChunkSize
406+-- > write = 'writeInChunksOf' A.defaultChunkSize
407--
407--
408-- | Write a byte stream to a file handle. Combines the bytes in chunks of size
408-- | Write a byte stream to a file handle. Combines the bytes in chunks of size
409-- up to 'A.defaultChunkSize' before writing. Note that the write behavior
409-- up to 'A.defaultChunkSize' before writing. Note that the write behavior
@@ -412,7 +412,7 @@ writeByChunksOf n h m = writeArrays h $ AS.arraysOf n m
412-- @since 0.7.0
412-- @since 0.7.0
413{-# INLINE write #-}
413{-# INLINE write #-}
414write :: MonadIO m => Handle -> SerialT m Word8 -> m ()
414write :: MonadIO m => Handle -> SerialT m Word8 -> m ()
415−write = writeByChunksOf defaultChunkSize
415+write = writeInChunksOf defaultChunkSize
416
416
417{-
417{-
418{-# INLINE write #-}
418{-# INLINE write #-}
src/Streamly/FileSystem/File.hs+19−18
@@ -63,7 +63,7 @@ module Streamly.FileSystem.File
63 -- -- * Array Read
63 -- -- * Array Read
64 -- , readArrayOf
64 -- , readArrayOf
65
65
66− , readArraysOfUpto
66+ , readArraysOf
67 -- , readArraysOf
67 -- , readArraysOf
68 , readArrays
68 , readArrays
69
69
@@ -72,7 +72,7 @@ module Streamly.FileSystem.File
72 -- , writeUtf8
72 -- , writeUtf8
73 -- , writeUtf8ByLines
73 -- , writeUtf8ByLines
74 -- , writeByFrames
74 -- , writeByFrames
75− , writeByChunks
75+ , writeInChunksOf
76
76
77 -- -- * Array Write
77 -- -- * Array Write
78 , writeArray
78 , writeArray
@@ -183,26 +183,27 @@ appendArray file arr = SIO.withFile file AppendMode (\h -> FH.writeArray h arr)
183-- Stream of Arrays IO
183-- Stream of Arrays IO
184-------------------------------------------------------------------------------
184-------------------------------------------------------------------------------
185
185
186−-- | @readArraysOfUpto size file@ reads a stream of arrays from file @file@.
186+-- | @readArraysOf size file@ reads a stream of arrays from file @file@.
187-- The maximum size of a single array is specified by @size@. The actual size
187-- The maximum size of a single array is specified by @size@. The actual size
188-- read may be less than or equal to @size@.
188-- read may be less than or equal to @size@.
189−{-# INLINABLE readArraysOfUpto #-}
189+{-# INLINABLE readArraysOf #-}
190−readArraysOfUpto :: (IsStream t, MonadCatch m, MonadIO m)
190+readArraysOf :: (IsStream t, MonadCatch m, MonadIO m)
191 => Int -> FilePath -> t m (Array Word8)
191 => Int -> FilePath -> t m (Array Word8)
192−readArraysOfUpto size file = withFile file ReadMode (FH.readArraysOfUpto size)
192+readArraysOf size file = withFile file ReadMode (FH.readArraysOf size)
193
193
194-- XXX read 'Array a' instead of Word8
194-- XXX read 'Array a' instead of Word8
195--
195--
196-- | @readArrays file@ reads a stream of arrays from file @file@.
196-- | @readArrays file@ reads a stream of arrays from file @file@.
197−-- The maximum size of a single array is limited to @defaultChunkSize@.
197+-- The maximum size of a single array is limited to @defaultChunkSize@. The
198+-- actual size read may be less than @defaultChunkSize@.
198--
199--
199−-- > readArrays = readArraysOfUpto defaultChunkSize
200+-- > readArrays = readArraysOf defaultChunkSize
200--
201--
201-- @since 0.7.0
202-- @since 0.7.0
202{-# INLINE readArrays #-}
203{-# INLINE readArrays #-}
203readArrays :: (IsStream t, MonadCatch m, MonadIO m)
204readArrays :: (IsStream t, MonadCatch m, MonadIO m)
204 => FilePath -> t m (Array Word8)
205 => FilePath -> t m (Array Word8)
205−readArrays = readArraysOfUpto A.defaultChunkSize
206+readArrays = readArraysOf A.defaultChunkSize
206
207
207-------------------------------------------------------------------------------
208-------------------------------------------------------------------------------
208-- Read File to Stream
209-- Read File to Stream
@@ -213,13 +214,13 @@ readArrays = readArraysOfUpto A.defaultChunkSize
213-- also control the read throughput in mbps or IOPS.
214-- also control the read throughput in mbps or IOPS.
214
215
215{-
216{-
216−-- | @readByChunksUpto chunkSize handle@ reads a byte stream from a file
217+-- | @readInChunksOf chunkSize handle@ reads a byte stream from a file
217-- handle, reads are performed in chunks of up to @chunkSize@. The stream ends
218-- handle, reads are performed in chunks of up to @chunkSize@. The stream ends
218-- as soon as EOF is encountered.
219-- as soon as EOF is encountered.
219--
220--
220−{-# INLINE readByChunksUpto #-}
221+{-# INLINE readInChunksOf #-}
221−readByChunksUpto :: (IsStream t, MonadIO m) => Int -> Handle -> t m Word8
222+readInChunksOf :: (IsStream t, MonadIO m) => Int -> Handle -> t m Word8
222−readByChunksUpto chunkSize h = A.flattenArrays $ readArraysOfUpto chunkSize h
223+readInChunksOf chunkSize h = A.flattenArrays $ readArraysOf chunkSize h
223-}
224-}
224
225
225-- TODO
226-- TODO
@@ -286,12 +287,12 @@ writeArrays = writeArraysMode WriteMode
286-- input elements.
287-- input elements.
287--
288--
288-- @since 0.7.0
289-- @since 0.7.0
289−{-# INLINE writeByChunks #-}
290+{-# INLINE writeInChunksOf #-}
290−writeByChunks :: (MonadAsync m, MonadCatch m)
291+writeInChunksOf :: (MonadAsync m, MonadCatch m)
291 => Int -> FilePath -> SerialT m Word8 -> m ()
292 => Int -> FilePath -> SerialT m Word8 -> m ()
292−writeByChunks n file xs = writeArrays file $ AS.arraysOf n xs
293+writeInChunksOf n file xs = writeArrays file $ AS.arraysOf n xs
293
294
294−-- > write = 'writeByChunks' A.defaultChunkSize
295+-- > write = 'writeInChunksOf' A.defaultChunkSize
295--
296--
296-- | Write a byte stream to a file. Combines the bytes in chunks of size
297-- | Write a byte stream to a file. Combines the bytes in chunks of size
297-- up to 'A.defaultChunkSize' before writing. If the file exists it is
298-- up to 'A.defaultChunkSize' before writing. If the file exists it is
@@ -301,7 +302,7 @@ writeByChunks n file xs = writeArrays file $ AS.arraysOf n xs
301-- @since 0.7.0
302-- @since 0.7.0
302{-# INLINE write #-}
303{-# INLINE write #-}
303write :: (MonadAsync m, MonadCatch m) => FilePath -> SerialT m Word8 -> m ()
304write :: (MonadAsync m, MonadCatch m) => FilePath -> SerialT m Word8 -> m ()
304−write = writeByChunks A.defaultChunkSize
305+write = writeInChunksOf A.defaultChunkSize
305
306
306{-
307{-
307{-# INLINE write #-}
308{-# INLINE write #-}
src/Streamly/FileSystem/Handle.hs+25−23
@@ -61,13 +61,13 @@ module Streamly.FileSystem.Handle
61 -- , readUtf8
61 -- , readUtf8
62 -- , readLines
62 -- , readLines
63 -- , readFrames
63 -- , readFrames
64− , readByChunksUpto
64+ , readInChunksOf
65
65
66 -- -- * Array Read
66 -- -- * Array Read
67 -- , readArrayUpto
67 -- , readArrayUpto
68 -- , readArrayOf
68 -- , readArrayOf
69
69
70− , readArraysOfUpto
70+ , readArraysOf
71 -- , readArraysOf
71 -- , readArraysOf
72 , readArrays
72 , readArrays
73
73
@@ -81,7 +81,7 @@ module Streamly.FileSystem.Handle
81 -- , writeUtf8
81 -- , writeUtf8
82 -- , writeUtf8ByLines
82 -- , writeUtf8ByLines
83 -- , writeByFrames
83 -- , writeByFrames
84− , writeByChunksOf
84+ , writeInChunksOf
85
85
86 -- -- * Array Write
86 -- -- * Array Write
87 , writeArray
87 , writeArray
@@ -187,13 +187,13 @@ writeArray h Array{..} = withForeignPtr aStart $ \p -> hPutBuf h p aLen
187-- Stream of Arrays IO
187-- Stream of Arrays IO
188-------------------------------------------------------------------------------
188-------------------------------------------------------------------------------
189
189
190−-- | @readArraysOfUpto size h@ reads a stream of arrays from file handle @h@.
190+-- | @readArraysOf size h@ reads a stream of arrays from file handle @h@.
191-- The maximum size of a single array is specified by @size@. The actual size
191-- The maximum size of a single array is specified by @size@. The actual size
192-- read may be less than or equal to @size@.
192-- read may be less than or equal to @size@.
193−{-# INLINABLE _readArraysOfUpto #-}
193+{-# INLINABLE _readArraysOf #-}
194−_readArraysOfUpto :: (IsStream t, MonadIO m)
194+_readArraysOf :: (IsStream t, MonadIO m)
195 => Int -> Handle -> t m (Array Word8)
195 => Int -> Handle -> t m (Array Word8)
196−_readArraysOfUpto size h = go
196+_readArraysOf size h = go
197 where
197 where
198 -- XXX use cons/nil instead
198 -- XXX use cons/nil instead
199 go = mkStream $ \_ yld _ stp -> do
199 go = mkStream $ \_ yld _ stp -> do
@@ -202,13 +202,14 @@ _readArraysOfUpto size h = go
202 then stp
202 then stp
203 else yld arr go
203 else yld arr go
204
204
205−-- | @readArraysOfUpto size handle@ reads a stream of arrays from the file
205+-- | @readArraysOf size handle@ reads a stream of arrays from the file
206-- handle @handle@. The maximum size of a single array is limited to @size@.
206-- handle @handle@. The maximum size of a single array is limited to @size@.
207+-- The actual size read may be less than or equal to @size@.
207--
208--
208-- @since 0.7.0
209-- @since 0.7.0
209−{-# INLINE_NORMAL readArraysOfUpto #-}
210+{-# INLINE_NORMAL readArraysOf #-}
210−readArraysOfUpto :: (IsStream t, MonadIO m) => Int -> Handle -> t m (Array Word8)
211+readArraysOf :: (IsStream t, MonadIO m) => Int -> Handle -> t m (Array Word8)
211−readArraysOfUpto size h = D.fromStreamD (D.Stream step ())
212+readArraysOf size h = D.fromStreamD (D.Stream step ())
212 where
213 where
213 {-# INLINE_LATE step #-}
214 {-# INLINE_LATE step #-}
214 step _ _ = do
215 step _ _ = do
@@ -222,14 +223,15 @@ readArraysOfUpto size h = D.fromStreamD (D.Stream step ())
222--
223--
223-- | @readArrays handle@ reads a stream of arrays from the specified file
224-- | @readArrays handle@ reads a stream of arrays from the specified file
224-- handle. The maximum size of a single array is limited to
225-- handle. The maximum size of a single array is limited to
226+-- @defaultChunkSize@. The actual size read may be less than or equal to
225-- @defaultChunkSize@.
227-- @defaultChunkSize@.
226--
228--
227−-- > readArrays = readArraysOfUpto defaultChunkSize
229+-- > readArrays = readArraysOf defaultChunkSize
228--
230--
229-- @since 0.7.0
231-- @since 0.7.0
230{-# INLINE readArrays #-}
232{-# INLINE readArrays #-}
231readArrays :: (IsStream t, MonadIO m) => Handle -> t m (Array Word8)
233readArrays :: (IsStream t, MonadIO m) => Handle -> t m (Array Word8)
232−readArrays = readArraysOfUpto defaultChunkSize
234+readArrays = readArraysOf defaultChunkSize
233
235
234-------------------------------------------------------------------------------
236-------------------------------------------------------------------------------
235-- Read File to Stream
237-- Read File to Stream
@@ -239,13 +241,13 @@ readArrays = readArraysOfUpto defaultChunkSize
239-- read requests at the same time. For serial case we can use async IO. We can
241-- read requests at the same time. For serial case we can use async IO. We can
240-- also control the read throughput in mbps or IOPS.
242-- also control the read throughput in mbps or IOPS.
241
243
242−-- | @readByChunksUpto chunkSize handle@ reads a byte stream from a file
244+-- | @readInChunksOf chunkSize handle@ reads a byte stream from a file
243-- handle, reads are performed in chunks of up to @chunkSize@.
245-- handle, reads are performed in chunks of up to @chunkSize@.
244--
246--
245-- @since 0.7.0
247-- @since 0.7.0
246−{-# INLINE readByChunksUpto #-}
248+{-# INLINE readInChunksOf #-}
247−readByChunksUpto :: (IsStream t, MonadIO m) => Int -> Handle -> t m Word8
249+readInChunksOf :: (IsStream t, MonadIO m) => Int -> Handle -> t m Word8
248−readByChunksUpto chunkSize h = AS.flatten $ readArraysOfUpto chunkSize h
250+readInChunksOf chunkSize h = AS.flatten $ readArraysOf chunkSize h
249
251
250-- TODO
252-- TODO
251-- Generate a stream of elements of the given type from a file 'Handle'.
253-- Generate a stream of elements of the given type from a file 'Handle'.
@@ -289,16 +291,16 @@ writeArraysPackedUpto n h xs = writeArrays h $ AS.compact n xs
289-- do not want buffering to occur at GHC level as well. Same thing applies to
291-- do not want buffering to occur at GHC level as well. Same thing applies to
290-- writes as well.
292-- writes as well.
291
293
292−-- | @writeByChunksOf chunkSize handle stream@ writes @stream@ to @handle@ in
294+-- | @writeInChunksOf chunkSize handle stream@ writes @stream@ to @handle@ in
293-- chunks of @chunkSize@. A write is performed to the IO device as soon as we
295-- chunks of @chunkSize@. A write is performed to the IO device as soon as we
294-- collect the required input size.
296-- collect the required input size.
295--
297--
296-- @since 0.7.0
298-- @since 0.7.0
297−{-# INLINE writeByChunksOf #-}
299+{-# INLINE writeInChunksOf #-}
298−writeByChunksOf :: MonadIO m => Int -> Handle -> SerialT m Word8 -> m ()
300+writeInChunksOf :: MonadIO m => Int -> Handle -> SerialT m Word8 -> m ()
299−writeByChunksOf n h m = writeArrays h $ AS.arraysOf n m
301+writeInChunksOf n h m = writeArrays h $ AS.arraysOf n m
300
302
301−-- > write = 'writeByChunksOf' A.defaultChunkSize
303+-- > write = 'writeInChunksOf' A.defaultChunkSize
302--
304--
303-- | Write a byte stream to a file handle. Combines the bytes in chunks of
305-- | Write a byte stream to a file handle. Combines the bytes in chunks of
304-- up to 'A.defaultChunkSize' before writing.
306-- up to 'A.defaultChunkSize' before writing.
@@ -306,7 +308,7 @@ writeByChunksOf n h m = writeArrays h $ AS.arraysOf n m
306-- @since 0.7.0
308-- @since 0.7.0
307{-# INLINE write #-}
309{-# INLINE write #-}
308write :: MonadIO m => Handle -> SerialT m Word8 -> m ()
310write :: MonadIO m => Handle -> SerialT m Word8 -> m ()
309−write = writeByChunksOf defaultChunkSize
311+write = writeInChunksOf defaultChunkSize
310
312
311{-
313{-
312{-# INLINE write #-}
314{-# INLINE write #-}
src/Streamly/Network/Client.hs+5−5
@@ -47,7 +47,7 @@ module Streamly.Network.Client
47 -- , writeUtf8
47 -- , writeUtf8
48 -- , writeUtf8ByLines
48 -- , writeUtf8ByLines
49 -- , writeByFrames
49 -- , writeByFrames
50− -- , writeByChunks
50+ -- , writeInChunksOf
51
51
52 -- -- * Array Write
52 -- -- * Array Write
53 -- , writeArray
53 -- , writeArray
@@ -133,15 +133,15 @@ writeArrays addr port xs =
133-- input elements.
133-- input elements.
134--
134--
135-- @since 0.7.0
135-- @since 0.7.0
136−{-# INLINE writeByChunks #-}
136+{-# INLINE writeInChunksOf #-}
137−writeByChunks
137+writeInChunksOf
138 :: (MonadCatch m, MonadAsync m)
138 :: (MonadCatch m, MonadAsync m)
139 => Int
139 => Int
140 -> (Word8, Word8, Word8, Word8)
140 -> (Word8, Word8, Word8, Word8)
141 -> PortNumber
141 -> PortNumber
142 -> SerialT m Word8
142 -> SerialT m Word8
143 -> m ()
143 -> m ()
144−writeByChunks n addr port m = writeArrays addr port $ AS.arraysOf n m
144+writeInChunksOf n addr port m = writeArrays addr port $ AS.arraysOf n m
145
145
146-- | Write a stream to the supplied IPv4 host address and port number.
146-- | Write a stream to the supplied IPv4 host address and port number.
147--
147--
@@ -149,4 +149,4 @@ writeByChunks n addr port m = writeArrays addr port $ AS.arraysOf n m
149{-# INLINE write #-}
149{-# INLINE write #-}
150write :: (MonadCatch m, MonadAsync m)
150write :: (MonadCatch m, MonadAsync m)
151 => (Word8, Word8, Word8, Word8) -> PortNumber -> SerialT m Word8 -> m ()
151 => (Word8, Word8, Word8, Word8) -> PortNumber -> SerialT m Word8 -> m ()
152−write = writeByChunks defaultChunkSize
152+write = writeInChunksOf defaultChunkSize
src/Streamly/Network/Socket.hs+18−18
@@ -56,7 +56,7 @@ module Streamly.Network.Socket
56 -- , writeUtf8
56 -- , writeUtf8
57 -- , writeUtf8ByLines
57 -- , writeUtf8ByLines
58 -- , writeByFrames
58 -- , writeByFrames
59− , writeByChunks
59+ , writeInChunksOf
60
60
61 -- -- * Array Write
61 -- -- * Array Write
62 , writeArray
62 , writeArray
@@ -154,9 +154,9 @@ readArrayUptoWith f size h = do
154-- handle it blocks until some data becomes available. If data is available
154-- handle it blocks until some data becomes available. If data is available
155-- then it immediately returns that data without blocking. It reads a maximum
155-- then it immediately returns that data without blocking. It reads a maximum
156-- of up to the size requested.
156-- of up to the size requested.
157−{-# INLINABLE readArrayUpto #-}
157+{-# INLINABLE readArrayOf #-}
158−readArrayUpto :: Int -> Socket -> IO (Array Word8)
158+readArrayOf :: Int -> Socket -> IO (Array Word8)
159−readArrayUpto = readArrayUptoWith recvBuf
159+readArrayOf = readArrayUptoWith recvBuf
160
160
161-------------------------------------------------------------------------------
161-------------------------------------------------------------------------------
162-- Array IO (output)
162-- Array IO (output)
@@ -217,14 +217,14 @@ readArraysUptoWith f size h = go
217 then stp
217 then stp
218 else yld arr go
218 else yld arr go
219
219
220−-- | @readArraysUpto size h@ reads a stream of arrays from file handle @h@.
220+-- | @readArraysOf size h@ reads a stream of arrays from file handle @h@.
221-- The maximum size of a single array is limited to @size@.
221-- The maximum size of a single array is limited to @size@.
222-- 'fromHandleArraysUpto' ignores the prevailing 'TextEncoding' and 'NewlineMode'
222-- 'fromHandleArraysUpto' ignores the prevailing 'TextEncoding' and 'NewlineMode'
223-- on the 'Handle'.
223-- on the 'Handle'.
224−{-# INLINABLE readArraysUpto #-}
224+{-# INLINABLE readArraysOf #-}
225−readArraysUpto :: (IsStream t, MonadIO m)
225+readArraysOf :: (IsStream t, MonadIO m)
226 => Int -> Socket -> t m (Array Word8)
226 => Int -> Socket -> t m (Array Word8)
227−readArraysUpto = readArraysUptoWith readArrayUpto
227+readArraysOf = readArraysUptoWith readArrayOf
228
228
229-- XXX read 'Array a' instead of Word8
229-- XXX read 'Array a' instead of Word8
230--
230--
@@ -236,7 +236,7 @@ readArraysUpto = readArraysUptoWith readArrayUpto
236-- @since 0.7.0
236-- @since 0.7.0
237{-# INLINE readArrays #-}
237{-# INLINE readArrays #-}
238readArrays :: (IsStream t, MonadIO m) => Socket -> t m (Array Word8)
238readArrays :: (IsStream t, MonadIO m) => Socket -> t m (Array Word8)
239−readArrays = readArraysUpto A.defaultChunkSize
239+readArrays = readArraysOf A.defaultChunkSize
240
240
241-------------------------------------------------------------------------------
241-------------------------------------------------------------------------------
242-- Read File to Stream
242-- Read File to Stream
@@ -247,13 +247,13 @@ readArrays = readArraysUpto A.defaultChunkSize
247-- also control the read throughput in mbps or IOPS.
247-- also control the read throughput in mbps or IOPS.
248
248
249{-
249{-
250−-- | @readByChunksUpto chunkSize handle@ reads a byte stream from a file
250+-- | @readInChunksOf chunkSize handle@ reads a byte stream from a file
251-- handle, reads are performed in chunks of up to @chunkSize@. The stream ends
251-- handle, reads are performed in chunks of up to @chunkSize@. The stream ends
252-- as soon as EOF is encountered.
252-- as soon as EOF is encountered.
253--
253--
254−{-# INLINE readByChunksUpto #-}
254+{-# INLINE readInChunksOf #-}
255−readByChunksUpto :: (IsStream t, MonadIO m) => Int -> Handle -> t m Word8
255+readInChunksOf :: (IsStream t, MonadIO m) => Int -> Handle -> t m Word8
256−readByChunksUpto chunkSize h = A.flattenArrays $ readArraysUpto chunkSize h
256+readInChunksOf chunkSize h = A.flattenArrays $ readArraysUpto chunkSize h
257-}
257-}
258
258
259-- TODO
259-- TODO
@@ -292,11 +292,11 @@ writeArrays h m = S.mapM_ (liftIO . writeArray h) m
292-- input elements.
292-- input elements.
293--
293--
294-- @since 0.7.0
294-- @since 0.7.0
295−{-# INLINE writeByChunks #-}
295+{-# INLINE writeInChunksOf #-}
296−writeByChunks :: MonadIO m => Int -> Socket -> SerialT m Word8 -> m ()
296+writeInChunksOf :: MonadIO m => Int -> Socket -> SerialT m Word8 -> m ()
297−writeByChunks n h m = writeArrays h $ AS.arraysOf n m
297+writeInChunksOf n h m = writeArrays h $ AS.arraysOf n m
298
298
299−-- > write = 'writeByChunks' A.defaultChunkSize
299+-- > write = 'writeInChunksOf' A.defaultChunkSize
300--
300--
301-- | Write a byte stream to a file handle. Combines the bytes in chunks of size
301-- | Write a byte stream to a file handle. Combines the bytes in chunks of size
302-- up to 'A.defaultChunkSize' before writing. Note that the write behavior
302-- up to 'A.defaultChunkSize' before writing. Note that the write behavior
@@ -305,7 +305,7 @@ writeByChunks n h m = writeArrays h $ AS.arraysOf n m
305-- @since 0.7.0
305-- @since 0.7.0
306{-# INLINE write #-}
306{-# INLINE write #-}
307write :: MonadIO m => Socket -> SerialT m Word8 -> m ()
307write :: MonadIO m => Socket -> SerialT m Word8 -> m ()
308−write = writeByChunks A.defaultChunkSize
308+write = writeInChunksOf A.defaultChunkSize
309
309
310{-
310{-
311{-# INLINE write #-}
311{-# INLINE write #-}