@@ -22,18 +22,18 @@ module Streamly.Internal.FileSystem.Handle
2222 -- , readUtf8
2323 -- , readLines
2424 -- , readFrames
25− , readRequestsOf
25+ , readWithBufferOf
2626
2727 , toStream
28− , toStreamRequestsOf
28+ , toStreamWithBufferOf
2929
3030 -- -- * Array Read
3131 -- , readArrayUpto
3232 -- , readArrayOf
3333 , readChunks
34− , readChunksRequestsOf
34+ , readChunksWithBufferOf
3535
36− , toChunksRequestsOf
36+ , toChunksWithBufferOf
3737 , toChunks
3838
3939 -- ** Write to Handle
@@ -42,20 +42,20 @@ module Streamly.Internal.FileSystem.Handle
4242 -- , writeUtf8
4343 -- , writeUtf8ByLines
4444 -- , writeByFrames
45− , writeRequestsOf
45+ , writeWithBufferOf
4646
4747 -- Byte stream write (Streams)
4848 , fromStream
49− , fromStreamInChunksOf
49+ , fromStreamWithBufferOf
5050
5151 -- -- * Array Write
5252 , writeArray
5353 , writeChunks
54− , writeChunksRequestsOf
54+ , writeChunksWithBufferOf
5555
5656 -- -- * Array stream Write
57− , fromStreamArrays
58− , fromStreamArraysInChunksOf
57+ , fromChunks
58+ , fromChunksWithBufferOf
5959
6060 -- -- * Random Access (Seek)
6161 -- -- | Unlike the streaming APIs listed above, these APIs apply to devices or
@@ -79,8 +79,8 @@ module Streamly.Internal.FileSystem.Handle
7979
8080 -- , readChunksFrom
8181 -- , readChunksFromTo
82− -- , readChunksFromToRequestsOf
83− -- , readChunksFromThenToRequestsOf
82+ -- , readChunksFromToWithBufferOf
83+ -- , readChunksFromThenToWithBufferOf
8484
8585 -- , writeIndex
8686 -- , writeFrom -- start writing at the given position
@@ -92,8 +92,8 @@ module Streamly.Internal.FileSystem.Handle
9292 --
9393 -- , writeChunksFrom
9494 -- , writeChunksFromTo
95− -- , writeChunksFromToRequestsOf
96− -- , writeChunksFromThenToRequestsOf
95+ -- , writeChunksFromToWithBufferOf
96+ -- , writeChunksFromThenToWithBufferOf
9797 )
9898where
9999
@@ -164,13 +164,13 @@ readArrayUpto size h = do
164164-- Stream of Arrays IO
165165-------------------------------------------------------------------------------
166166
167−-- | @toChunksRequestsOf size h@ reads a stream of arrays from file handle @h@.
167+-- | @toChunksWithBufferOf size h@ reads a stream of arrays from file handle @h@.
168168-- The maximum size of a single array is specified by @size@. The actual size
169169-- read may be less than or equal to @size@.
170−{-# INLINABLE _toChunksRequestsOf #-}
171−_toChunksRequestsOf :: (IsStream t, MonadIO m)
170+{-# INLINABLE _toChunksWithBufferOf #-}
171+_toChunksWithBufferOf :: (IsStream t, MonadIO m)
172172 => Int -> Handle -> t m (Array Word8)
173−_toChunksRequestsOf size h = go
173+_toChunksWithBufferOf size h = go
174174 where
175175 -- XXX use cons/nil instead
176176 go = mkStream $ \_ yld _ stp -> do
@@ -179,14 +179,14 @@ _toChunksRequestsOf size h = go
179179 then stp
180180 else yld arr go
181181
182−-- | @toChunksRequestsOf size handle@ reads a stream of arrays from the file
182+-- | @toChunksWithBufferOf size handle@ reads a stream of arrays from the file
183183-- handle @handle@. The maximum size of a single array is limited to @size@.
184184-- The actual size read may be less than or equal to @size@.
185185--
186186-- @since 0.7.0
187−{-# INLINE_NORMAL toChunksRequestsOf #-}
188−toChunksRequestsOf :: (IsStream t, MonadIO m) => Int -> Handle -> t m (Array Word8)
189−toChunksRequestsOf size h = D.fromStreamD (D.Stream step ())
187+{-# INLINE_NORMAL toChunksWithBufferOf #-}
188+toChunksWithBufferOf :: (IsStream t, MonadIO m) => Int -> Handle -> t m (Array Word8)
189+toChunksWithBufferOf size h = D.fromStreamD (D.Stream step ())
190190 where
191191 {-# INLINE_LATE step #-}
192192 step _ _ = do
@@ -196,14 +196,15 @@ toChunksRequestsOf size h = D.fromStreamD (D.Stream step ())
196196 0 -> D.Stop
197197 _ -> D.Yield arr ()
198198
199−-- | Unfold the tuple @(size, handle)@ into a stream of 'Word8' arrays. The
200−-- stream consists of arrays representing chunks of data read from the handle.
201−-- The size of an array in the stream is less than or equal to @size@.
199+-- | Unfold the tuple @(bufsize, handle)@ into a stream of 'Word8' arrays.
200+-- Read requests to the IO device are performed using a buffer of size
201+-- @bufsize@. The size of an array in the resulting stream is always less than
202+-- or equal to @bufsize@.
202203--
203204-- @since 0.7.0
204−{-# INLINE_NORMAL readChunksRequestsOf #-}
205−readChunksRequestsOf :: MonadIO m => Unfold m (Int, Handle) (Array Word8)
206−readChunksRequestsOf = Unfold step return
205+{-# INLINE_NORMAL readChunksWithBufferOf #-}
206+readChunksWithBufferOf :: MonadIO m => Unfold m (Int, Handle) (Array Word8)
207+readChunksWithBufferOf = Unfold step return
207208 where
208209 {-# INLINE_LATE step #-}
209210 step (size, h) = do
@@ -220,12 +221,12 @@ readChunksRequestsOf = Unfold step return
220221-- @defaultChunkSize@. The actual size read may be less than or equal to
221222-- @defaultChunkSize@.
222223--
223−-- > toChunks = toChunksRequestsOf defaultChunkSize
224+-- > toChunks = toChunksWithBufferOf defaultChunkSize
224225--
225226-- @since 0.7.0
226227{-# INLINE toChunks #-}
227228toChunks :: (IsStream t, MonadIO m) => Handle -> t m (Array Word8)
228−toChunks = toChunksRequestsOf defaultChunkSize
229+toChunks = toChunksWithBufferOf defaultChunkSize
229230
230231-- | Unfolds a handle into a stream of 'Word8' arrays. Requests to the IO
231232-- device are performed using a buffer of size
@@ -236,7 +237,7 @@ toChunks = toChunksRequestsOf defaultChunkSize
236237-- @since 0.7.0
237238{-# INLINE readChunks #-}
238239readChunks :: MonadIO m => Unfold m Handle (Array Word8)
239−readChunks = UF.supplyFirst readChunksRequestsOf defaultChunkSize
240+readChunks = UF.supplyFirst readChunksWithBufferOf defaultChunkSize
240241
241242-------------------------------------------------------------------------------
242243-- Read File to Stream
@@ -246,21 +247,21 @@ readChunks = UF.supplyFirst readChunksRequestsOf defaultChunkSize
246247-- read requests at the same time. For serial case we can use async IO. We can
247248-- also control the read throughput in mbps or IOPS.
248249
249−-- | Unfolds the tuple @(chunksize, handle)@ into a byte stream, read requests
250−-- to the IO device are performed using buffers of @chunkSize@.
250+-- | Unfolds the tuple @(bufsize, handle)@ into a byte stream, read requests
251+-- to the IO device are performed using buffers of @bufsize@.
251252--
252253-- @since 0.7.0
253−{-# INLINE readRequestsOf #-}
254−readRequestsOf :: MonadIO m => Unfold m (Int, Handle) Word8
255−readRequestsOf = UF.concat readChunksRequestsOf A.read
254+{-# INLINE readWithBufferOf #-}
255+readWithBufferOf :: MonadIO m => Unfold m (Int, Handle) Word8
256+readWithBufferOf = UF.concat readChunksWithBufferOf A.read
256257
257−-- | @toStreamRequestsOf chunkSize handle@ reads a byte stream from a file
258−-- handle, reads are performed in chunks of up to @chunkSize@.
258+-- | @toStreamWithBufferOf bufsize handle@ reads a byte stream from a file
259+-- handle, reads are performed in chunks of up to @bufsize@.
259260--
260261-- /Internal/
261−{-# INLINE toStreamRequestsOf #-}
262−toStreamRequestsOf :: (IsStream t, MonadIO m) => Int -> Handle -> t m Word8
263−toStreamRequestsOf chunkSize h = AS.concat $ toChunksRequestsOf chunkSize h
262+{-# INLINE toStreamWithBufferOf #-}
263+toStreamWithBufferOf :: (IsStream t, MonadIO m) => Int -> Handle -> t m Word8
264+toStreamWithBufferOf chunkSize h = AS.concat $ toChunksWithBufferOf chunkSize h
264265
265266-- TODO
266267-- Generate a stream of elements of the given type from a file 'Handle'.
@@ -273,7 +274,7 @@ toStreamRequestsOf chunkSize h = AS.concat $ toChunksRequestsOf chunkSize h
273274-- @since 0.7.0
274275{-# INLINE read #-}
275276read :: MonadIO m => Unfold m Handle Word8
276−read = UF.supplyFirst readRequestsOf defaultChunkSize
277+read = UF.supplyFirst readWithBufferOf defaultChunkSize
277278
278279-- | Generate a byte stream from a file 'Handle'.
279280--
@@ -313,33 +314,33 @@ writeArray h Array{..} = withForeignPtr aStart $ \p -> hPutBuf h p aLen
313314-- | Write a stream of arrays to a handle.
314315--
315316-- @since 0.7.0
316−{-# INLINE fromStreamArrays #-}
317−fromStreamArrays :: (MonadIO m, Storable a)
317+{-# INLINE fromChunks #-}
318+fromChunks :: (MonadIO m, Storable a)
318319 => Handle -> SerialT m (Array a) -> m ()
319−fromStreamArrays h m = S.mapM_ (liftIO . writeArray h) m
320+fromChunks h m = S.mapM_ (liftIO . writeArray h) m
320321
321−-- | @fromStreamArraysInChunksOf chunkSize handle stream@ writes a stream of arrays
322−-- to @handle@ after coalescing the adjacent arrays in chunks of @chunkSize@.
322+-- | @fromChunksWithBufferOf bufsize handle stream@ writes a stream of arrays
323+-- to @handle@ after coalescing the adjacent arrays in chunks of @bufsize@.
323324-- The chunk size is only a maximum and the actual writes could be smaller as
324325-- we do not split the arrays to fit exactly to the specified size.
325326--
326327-- @since 0.7.0
327−{-# INLINE fromStreamArraysInChunksOf #-}
328−fromStreamArraysInChunksOf :: (MonadIO m, Storable a)
328+{-# INLINE fromChunksWithBufferOf #-}
329+fromChunksWithBufferOf :: (MonadIO m, Storable a)
329330 => Int -> Handle -> SerialT m (Array a) -> m ()
330−fromStreamArraysInChunksOf n h xs = fromStreamArrays h $ AS.compact n xs
331+fromChunksWithBufferOf n h xs = fromChunks h $ AS.compact n xs
331332
332−-- | @fromStreamInChunksOf chunkSize handle stream@ writes @stream@ to @handle@ in
333−-- chunks of @chunkSize@. A write is performed to the IO device as soon as we
333+-- | @fromStreamWithBufferOf bufsize handle stream@ writes @stream@ to @handle@
334+-- in chunks of @bufsize@. A write is performed to the IO device as soon as we
334335-- collect the required input size.
335336--
336337-- @since 0.7.0
337−{-# INLINE fromStreamInChunksOf #-}
338−fromStreamInChunksOf :: MonadIO m => Int -> Handle -> SerialT m Word8 -> m ()
339−fromStreamInChunksOf n h m = fromStreamArrays h $ S.arraysOf n m
340−-- fromStreamInChunksOf n h m = fromStreamArrays h $ AS.arraysOf n m
338+{-# INLINE fromStreamWithBufferOf #-}
339+fromStreamWithBufferOf :: MonadIO m => Int -> Handle -> SerialT m Word8 -> m ()
340+fromStreamWithBufferOf n h m = fromChunks h $ S.arraysOf n m
341+-- fromStreamWithBufferOf n h m = fromChunks h $ AS.arraysOf n m
341342
342−-- > write = 'writeRequestsOf' A.defaultChunkSize
343+-- > write = 'writeWithBufferOf' A.defaultChunkSize
343344--
344345-- | Write a byte stream to a file handle. Accumulates the input in chunks of
345346-- up to 'Streamly.Internal.Memory.Array.Types.defaultChunkSize' before writing.
@@ -350,7 +351,7 @@ fromStreamInChunksOf n h m = fromStreamArrays h $ S.arraysOf n m
350351-- @since 0.7.0
351352{-# INLINE fromStream #-}
352353fromStream :: MonadIO m => Handle -> SerialT m Word8 -> m ()
353−fromStream = fromStreamInChunksOf defaultChunkSize
354+fromStream = fromStreamWithBufferOf defaultChunkSize
354355
355356-- | Write a stream of arrays to a handle. Each array in the stream is written
356357-- to the device as a separate IO request.
@@ -360,17 +361,17 @@ fromStream = fromStreamInChunksOf defaultChunkSize
360361writeChunks :: (MonadIO m, Storable a) => Handle -> Fold m (Array a) ()
361362writeChunks h = FL.drainBy (liftIO . writeArray h)
362363
363−-- | @writeChunksRequestsOf chunkSize handle@ writes a stream of arrays
364−-- to @handle@ after coalescing the adjacent arrays in chunks of @chunkSize@.
364+-- | @writeChunksWithBufferOf bufsize handle@ writes a stream of arrays
365+-- to @handle@ after coalescing the adjacent arrays in chunks of @bufsize@.
365366-- We never split an array, if a single array is bigger than the specified size
366367-- it emitted as it is. Multiple arrays are coalesed as long as the total size
367368-- remains below the specified size.
368369--
369370-- @since 0.7.0
370−{-# INLINE writeChunksRequestsOf #-}
371−writeChunksRequestsOf :: (MonadIO m, Storable a)
371+{-# INLINE writeChunksWithBufferOf #-}
372+writeChunksWithBufferOf :: (MonadIO m, Storable a)
372373 => Int -> Handle -> Fold m (Array a) ()
373−writeChunksRequestsOf n h = lpackArraysChunksOf n (writeChunks h)
374+writeChunksWithBufferOf n h = lpackArraysChunksOf n (writeChunks h)
374375
375376-- GHC buffer size dEFAULT_FD_BUFFER_SIZE=8192 bytes.
376377--
@@ -380,16 +381,16 @@ writeChunksRequestsOf n h = lpackArraysChunksOf n (writeChunks h)
380381-- do not want buffering to occur at GHC level as well. Same thing applies to
381382-- writes as well.
382383
383−-- | @writeRequestsOf reqSize handle@ writes the input stream to @handle@.
384+-- | @writeWithBufferOf reqSize handle@ writes the input stream to @handle@.
384385-- Bytes in the input stream are collected into a buffer until we have a chunk
385386-- of @reqSize@ and then written to the IO device.
386387--
387388-- @since 0.7.0
388−{-# INLINE writeRequestsOf #-}
389−writeRequestsOf :: MonadIO m => Int -> Handle -> Fold m Word8 ()
390−writeRequestsOf n h = FL.lchunksOf n (writeNUnsafe n) (writeChunks h)
389+{-# INLINE writeWithBufferOf #-}
390+writeWithBufferOf :: MonadIO m => Int -> Handle -> Fold m Word8 ()
391+writeWithBufferOf n h = FL.lchunksOf n (writeNUnsafe n) (writeChunks h)
391392
392−-- > write = 'writeRequestsOf' A.defaultChunkSize
393+-- > write = 'writeWithBufferOf' A.defaultChunkSize
393394--
394395-- | Write a byte stream to a file handle. Accumulates the input in chunks of
395396-- up to 'Streamly.Internal.Memory.Array.Types.defaultChunkSize' before writing
@@ -398,7 +399,7 @@ writeRequestsOf n h = FL.lchunksOf n (writeNUnsafe n) (writeChunks h)
398399-- @since 0.7.0
399400{-# INLINE write #-}
400401write :: MonadIO m => Handle -> Fold m Word8 ()
401−write = writeRequestsOf defaultChunkSize
402+write = writeWithBufferOf defaultChunkSize
402403
403404{-
404405{-# INLINE write #-}