on master help sign in
export array stream read/write ops
commit26715e2983e40710e4d07a06302a148c89aabc7c authorHarendra Kumar <harendra.kumar@gmail.com> dateTue 8 Oct 2019, 13:24 (7 years ago) parent3de89fe
2 files changed+17
src/Streamly/FileSystem/Handle.hs+2 src/Streamly/Internal/FileSystem/Handle.hs+15
src/Streamly/FileSystem/Handle.hs+2
@@ -64,6 +64,7 @@ module Streamly.FileSystem.Handle
6464 -- , readLines
6565 -- , readFrames
6666 , readInChunksOf
67+ , readArraysOf
6768
6869 -- ** Write to Handle
6970 -- | 'TextEncoding', 'NewLineMode', and 'Buffering' options of the
@@ -76,6 +77,7 @@ module Streamly.FileSystem.Handle
7677 -- , writeUtf8ByLines
7778 -- , writeByFrames
7879 , writeInChunksOf
80+ , writeArrays
7981
8082 -- -- * Random Access (Seek)
8183 -- -- | Unlike the streaming APIs listed above, these APIs apply to devices or
src/Streamly/Internal/FileSystem/Handle.hs+15
@@ -30,6 +30,8 @@ module Streamly.Internal.FileSystem.Handle
3030 -- -- * Array Read
3131 -- , readArrayUpto
3232 -- , readArrayOf
33+ , readArraysOf
34+ , readArrays
3335
3436 , toStreamArraysOf
3537 , toStreamArrays
@@ -175,6 +177,11 @@ toStreamArraysOf size h = D.fromStreamD (D.Stream step ())
175177 0 -> D.Stop
176178 _ -> D.Yield arr ()
177179
180+-- | Unfold the tuple @(size, handle)@ into a stream of 'Word8' arrays. The
181+-- stream consists of arrays representing chunks of data read from the handle.
182+-- The maximum size of a single array is limited to @size@.
183+--
184+-- @since 0.7.0
178185{-# INLINE_NORMAL readArraysOf #-}
179186readArraysOf :: MonadIO m => Unfold m (Int, Handle) (Array Word8)
180187readArraysOf = Unfold step return
@@ -201,6 +208,14 @@ readArraysOf = Unfold step return
201208toStreamArrays :: (IsStream t, MonadIO m) => Handle -> t m (Array Word8)
202209toStreamArrays = toStreamArraysOf defaultChunkSize
203210
211+-- | Unfolds a handle into a stream of 'Word8' arrays. The maximum size of a
212+-- single array is limited to @defaultChunkSize@.
213+--
214+-- @since 0.7.0
215+{-# INLINE readArrays #-}
216+readArrays :: MonadIO m => Unfold m Handle (Array Word8)
217+readArrays = UF.first readArraysOf defaultChunkSize
218+
204219-------------------------------------------------------------------------------
205220-- Read File to Stream
206221-------------------------------------------------------------------------------