on master help sign in
export array stream read/write ops
26715e2Harendra Kumar
src/Streamly/FileSystem/Handle.hs+2
@@ -64,6 +64,7 @@ module Streamly.FileSystem.Handle
64 -- , readLines
64 -- , readLines
65 -- , readFrames
65 -- , readFrames
66 , readInChunksOf
66 , readInChunksOf
67+ , readArraysOf
67
68
68 -- ** Write to Handle
69 -- ** Write to Handle
69 -- | 'TextEncoding', 'NewLineMode', and 'Buffering' options of the
70 -- | 'TextEncoding', 'NewLineMode', and 'Buffering' options of the
@@ -76,6 +77,7 @@ module Streamly.FileSystem.Handle
76 -- , writeUtf8ByLines
77 -- , writeUtf8ByLines
77 -- , writeByFrames
78 -- , writeByFrames
78 , writeInChunksOf
79 , writeInChunksOf
80+ , writeArrays
79
81
80 -- -- * Random Access (Seek)
82 -- -- * Random Access (Seek)
81 -- -- | Unlike the streaming APIs listed above, these APIs apply to devices or
83 -- -- | 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
30 -- -- * Array Read
30 -- -- * Array Read
31 -- , readArrayUpto
31 -- , readArrayUpto
32 -- , readArrayOf
32 -- , readArrayOf
33+ , readArraysOf
34+ , readArrays
33
35
34 , toStreamArraysOf
36 , toStreamArraysOf
35 , toStreamArrays
37 , toStreamArrays
@@ -175,6 +177,11 @@ toStreamArraysOf size h = D.fromStreamD (D.Stream step ())
175 0 -> D.Stop
177 0 -> D.Stop
176 _ -> D.Yield arr ()
178 _ -> D.Yield arr ()
177
179
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
178{-# INLINE_NORMAL readArraysOf #-}
185{-# INLINE_NORMAL readArraysOf #-}
179readArraysOf :: MonadIO m => Unfold m (Int, Handle) (Array Word8)
186readArraysOf :: MonadIO m => Unfold m (Int, Handle) (Array Word8)
180readArraysOf = Unfold step return
187readArraysOf = Unfold step return
@@ -201,6 +208,14 @@ readArraysOf = Unfold step return
201toStreamArrays :: (IsStream t, MonadIO m) => Handle -> t m (Array Word8)
208toStreamArrays :: (IsStream t, MonadIO m) => Handle -> t m (Array Word8)
202toStreamArrays = toStreamArraysOf defaultChunkSize
209toStreamArrays = toStreamArraysOf defaultChunkSize
203
210
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+
204-------------------------------------------------------------------------------
219-------------------------------------------------------------------------------
205-- Read File to Stream
220-- Read File to Stream
206-------------------------------------------------------------------------------
221-------------------------------------------------------------------------------