on master help sign in
Rename some filesystem APIs
commitaf68c08a71e7279fe4017a4b5bf7ff2b0f6d1ad1 authorRanjeet Kumar Ranjan <ranjeetr@composewell.com> dateMon 14 Mar 2022, 16:01 (5 years ago) parent0eadd04
12 files changed+225−194
benchmark/NanoBenchmarks.hs+1−1 benchmark/Streamly/Benchmark/Data/Array/Stream/Foreign.hs+8−8 benchmark/Streamly/Benchmark/FileSystem/Handle/Read.hs+7−7 benchmark/Streamly/Benchmark/FileSystem/Handle/ReadWrite.hs+27−28 benchmark/Streamly/Benchmark/Prelude/Serial/Exceptions.hs+4−4 benchmark/Streamly/Benchmark/Prelude/Serial/Split.hs+1−1 benchmark/Streamly/Benchmark/Unicode/Stream.hs+1−1 src/Streamly/FileSystem/Handle.hs+9−3 src/Streamly/Internal/Console/Stdio.hs+4−4 src/Streamly/Internal/FileSystem/File.hs+39−37 src/Streamly/Internal/FileSystem/Handle.hs+117−93 test/Streamly/Test/FileSystem/Handle.hs+7−7
benchmark/NanoBenchmarks.hs+1−1
@@ -114,7 +114,7 @@ main = do
114114 defaultMain [mkBenchText "splitOn abc...xyz" inText $ do
115115 (S.length $ Internal.splitOnSeq (A.fromList $ map (fromIntegral . ord)
116116 "abcdefghijklmnopqrstuvwxyz") FL.drain
117− $ IFH.toBytes inText) >>= print
117+ $ IFH.getBytes inText) >>= print
118118 ]
119119 where
120120
benchmark/Streamly/Benchmark/Data/Array/Stream/Foreign.hs+8−8
@@ -81,7 +81,7 @@ benchIO name src sink =
8181-- | Get the last byte from a file bytestream.
8282toChunksLast :: Handle -> IO (Maybe Word8)
8383toChunksLast inh = do
84− let s = Handle.toChunks inh
84+ let s = Handle.getChunks inh
8585 larr <- Stream.last s
8686 return $ case larr of
8787 Nothing -> Nothing
@@ -95,7 +95,7 @@ inspect $ 'toChunksLast `hasNoType` ''Step
9595-- | Count the number of bytes in a file.
9696toChunksSumLengths :: Handle -> IO Int
9797toChunksSumLengths inh =
98− let s = Handle.toChunks inh
98+ let s = Handle.getChunks inh
9999 in Stream.sum (Stream.map Array.length s)
100100
101101#ifdef INSPECTION
@@ -107,7 +107,7 @@ inspect $ 'toChunksSumLengths `hasNoType` ''Step
107107toChunksCountBytes :: Handle -> IO Word8
108108toChunksCountBytes inh = do
109109 let foldlArr' f z = runIdentity . Stream.foldl' f z . Array.toStream
110− let s = Handle.toChunks inh
110+ let s = Handle.getChunks inh
111111 Stream.foldl' (\acc arr -> acc + foldlArr' (+) 0 arr) 0 s
112112
113113#ifdef INSPECTION
@@ -117,7 +117,7 @@ inspect $ 'toChunksCountBytes `hasNoType` ''Step
117117
118118toChunksDecodeUtf8Arrays :: Handle -> IO ()
119119toChunksDecodeUtf8Arrays =
120− Stream.drain . Unicode.decodeUtf8Arrays . Handle.toChunks
120+ Stream.drain . Unicode.decodeUtf8Arrays . Handle.getChunks
121121
122122#ifdef INSPECTION
123123inspect $ hasNoTypeClasses 'toChunksDecodeUtf8Arrays
@@ -131,7 +131,7 @@ inspect $ hasNoTypeClasses 'toChunksDecodeUtf8Arrays
131131-- | Count the number of lines in a file.
132132toChunksSplitOnSuffix :: Handle -> IO Int
133133toChunksSplitOnSuffix =
134− Stream.length . ArrayStream.splitOnSuffix 10 . Handle.toChunks
134+ Stream.length . ArrayStream.splitOnSuffix 10 . Handle.getChunks
135135
136136#ifdef INSPECTION
137137inspect $ hasNoTypeClasses 'toChunksSplitOnSuffix
@@ -141,7 +141,7 @@ inspect $ 'toChunksSplitOnSuffix `hasNoType` ''Step
141141-- XXX use a word splitting combinator instead of splitOn and test it.
142142-- | Count the number of words in a file.
143143toChunksSplitOn :: Handle -> IO Int
144−toChunksSplitOn = Stream.length . ArrayStream.splitOn 32 . Handle.toChunks
144+toChunksSplitOn = Stream.length . ArrayStream.splitOn 32 . Handle.getChunks
145145
146146#ifdef INSPECTION
147147inspect $ hasNoTypeClasses 'toChunksSplitOn
@@ -181,7 +181,7 @@ copyChunksSplitInterposeSuffix inh outh =
181181 Stream.fold (Handle.write outh)
182182 $ ArrayStream.interposeSuffix 10
183183 $ ArrayStream.splitOnSuffix 10
184− $ Handle.toChunks inh
184+ $ Handle.getChunks inh
185185
186186#ifdef INSPECTION
187187inspect $ hasNoTypeClassesExcept 'copyChunksSplitInterposeSuffix [''Storable]
@@ -196,7 +196,7 @@ copyChunksSplitInterpose inh outh =
196196 $ ArrayStream.interpose 32
197197 -- XXX this is not correct word splitting combinator
198198 $ ArrayStream.splitOn 32
199− $ Handle.toChunks inh
199+ $ Handle.getChunks inh
200200
201201#ifdef INSPECTION
202202inspect $ hasNoTypeClassesExcept 'copyChunksSplitInterpose [''Storable]
benchmark/Streamly/Benchmark/FileSystem/Handle/Read.hs+7−7
@@ -183,25 +183,25 @@ o_1_space_reduce_read env =
183183-------------------------------------------------------------------------------
184184
185185-- | Count the number of lines in a file.
186−toChunksConcatUnfoldCountLines :: Handle -> IO Int
187−toChunksConcatUnfoldCountLines inh =
186+getChunksConcatUnfoldCountLines :: Handle -> IO Int
187+getChunksConcatUnfoldCountLines inh =
188188 S.length
189189 $ IUS.lines FL.drain
190190 $ SS.decodeLatin1
191191 -- XXX replace with toBytes
192− $ S.unfoldMany A.read (IFH.toChunks inh)
192+ $ S.unfoldMany A.read (IFH.getChunks inh)
193193
194194#ifdef INSPECTION
195−inspect $ hasNoTypeClasses 'toChunksConcatUnfoldCountLines
196−inspect $ 'toChunksConcatUnfoldCountLines `hasNoType` ''Step
197−inspect $ 'toChunksConcatUnfoldCountLines `hasNoType` ''D.ConcatMapUState
195+inspect $ hasNoTypeClasses 'getChunksConcatUnfoldCountLines
196+inspect $ 'getChunksConcatUnfoldCountLines `hasNoType` ''Step
197+inspect $ 'getChunksConcatUnfoldCountLines `hasNoType` ''D.ConcatMapUState
198198#endif
199199
200200o_1_space_reduce_toBytes :: BenchEnv -> [Benchmark]
201201o_1_space_reduce_toBytes env =
202202 [ bgroup "reduce/toBytes"
203203 [ mkBench "US.lines . SS.decodeLatin1" env $ \inh _ ->
204− toChunksConcatUnfoldCountLines inh
204+ getChunksConcatUnfoldCountLines inh
205205 ]
206206 ]
207207
benchmark/Streamly/Benchmark/FileSystem/Handle/ReadWrite.hs+27−28
@@ -53,7 +53,7 @@ import Test.Inspection
5353
5454-- | Copy file
5555copyChunks :: Handle -> Handle -> IO ()
56−copyChunks inh outh = S.fold (IFH.writeChunks outh) $ IFH.toChunks inh
56+copyChunks inh outh = S.fold (IFH.writeChunks outh) $ IFH.getChunks inh
5757
5858#ifdef INSPECTION
5959inspect $ hasNoTypeClasses 'copyChunks
@@ -62,7 +62,7 @@ inspect $ 'copyChunks `hasNoType` ''Step
6262
6363o_1_space_copy_chunked :: BenchEnv -> [Benchmark]
6464o_1_space_copy_chunked env =
65− [ bgroup "copy/toChunks"
65+ [ bgroup "copy/getChunks"
6666 [ mkBench "toNull" env $ \inH _ ->
6767 copyChunks inH (nullH env)
6868 , mkBench "raw" env $ \inH outH ->
@@ -114,17 +114,17 @@ inspect $ 'readFromBytesNull `hasNoType` ''D.FoldMany
114114#endif
115115
116116-- | Send the file contents ('defaultChunkSize') to /dev/null
117−readWithBufferOfFromBytesNull :: Handle -> Handle -> IO ()
118−readWithBufferOfFromBytesNull inh devNull =
117+readWithFromBytesNull :: Handle -> Handle -> IO ()
118+readWithFromBytesNull inh devNull =
119119 IFH.putBytes devNull
120− $ S.unfold FH.readWithBufferOf (defaultChunkSize, inh)
120+ $ S.unfold FH.readWith (defaultChunkSize, inh)
121121
122122#ifdef INSPECTION
123−inspect $ hasNoTypeClasses 'readWithBufferOfFromBytesNull
124−inspect $ 'readWithBufferOfFromBytesNull `hasNoType` ''Step
125−inspect $ 'readWithBufferOfFromBytesNull `hasNoType` ''MAS.SpliceState
126−inspect $ 'readWithBufferOfFromBytesNull `hasNoType` ''AT.ArrayUnsafe -- FH.fromBytes/S.arraysOf
127−inspect $ 'readWithBufferOfFromBytesNull `hasNoType` ''D.FoldMany
123+inspect $ hasNoTypeClasses 'readWithFromBytesNull
124+inspect $ 'readWithFromBytesNull `hasNoType` ''Step
125+inspect $ 'readWithFromBytesNull `hasNoType` ''MAS.SpliceState
126+inspect $ 'readWithFromBytesNull `hasNoType` ''AT.ArrayUnsafe -- FH.fromBytes/S.arraysOf
127+inspect $ 'readWithFromBytesNull `hasNoType` ''D.FoldMany
128128#endif
129129
130130-- | Send the chunk content ('defaultChunkSize') to /dev/null
@@ -138,41 +138,40 @@ _readChunks inh devNull = IUF.fold fld unf inh
138138 unf = IUF.many A.read FH.readChunks
139139
140140-- | Send the chunk content to /dev/null
141−-- Implicitly benchmarked via 'readWithBufferOfFromBytesNull'
142−_readChunksWithBufferOf :: Handle -> Handle -> IO ()
143−_readChunksWithBufferOf inh devNull = IUF.fold fld unf (defaultChunkSize, inh)
141+-- Implicitly benchmarked via 'readWithFromBytesNull'
142+_readChunksWith :: Handle -> Handle -> IO ()
143+_readChunksWith inh devNull = IUF.fold fld unf (defaultChunkSize, inh)
144144
145145 where
146146
147147 fld = FH.write devNull
148− unf = IUF.many A.read FH.readChunksWithBufferOf
149−
148+ unf = IUF.many A.read FH.readChunksWith
150149
151150o_1_space_copy_fromBytes :: BenchEnv -> [Benchmark]
152151o_1_space_copy_fromBytes env =
153152 [ bgroup "copy/putBytes"
154153 [ mkBench "rawToNull" env $ \inh _ ->
155154 readFromBytesNull inh (nullH env)
156− , mkBench "FH.readWithBufferOf" env $ \inh _ ->
157− readWithBufferOfFromBytesNull inh (nullH env)
155+ , mkBench "FH.readWith" env $ \inh _ ->
156+ readWithFromBytesNull inh (nullH env)
158157 ]
159158 ]
160159
161160-- | Send the file contents ('defaultChunkSize') to /dev/null
162−writeReadWithBufferOf :: Handle -> Handle -> IO ()
163−writeReadWithBufferOf inh devNull = IUF.fold fld unf (defaultChunkSize, inh)
161+writeReadWith :: Handle -> Handle -> IO ()
162+writeReadWith inh devNull = IUF.fold fld unf (defaultChunkSize, inh)
164163
165164 where
166165
167− fld = FH.writeWithBufferOf defaultChunkSize devNull
168− unf = FH.readWithBufferOf
166+ fld = FH.writeWith defaultChunkSize devNull
167+ unf = FH.readWith
169168
170169#ifdef INSPECTION
171−inspect $ hasNoTypeClasses 'writeReadWithBufferOf
172−inspect $ 'writeReadWithBufferOf `hasNoType` ''Step
173−inspect $ 'writeReadWithBufferOf `hasNoType` ''IUF.ConcatState -- FH.read/UF.many
174−inspect $ 'writeReadWithBufferOf `hasNoType` ''MA.ReadUState -- FH.read/A.read
175−inspect $ 'writeReadWithBufferOf `hasNoType` ''AT.ArrayUnsafe -- FH.write/writeNUnsafe
170+inspect $ hasNoTypeClasses 'writeReadWith
171+inspect $ 'writeReadWith `hasNoType` ''Step
172+inspect $ 'writeReadWith `hasNoType` ''IUF.ConcatState -- FH.read/UF.many
173+inspect $ 'writeReadWith `hasNoType` ''MA.ReadUState -- FH.read/A.read
174+inspect $ 'writeReadWith `hasNoType` ''AT.ArrayUnsafe -- FH.write/writeNUnsafe
176175#endif
177176
178177-- | Send the file contents ('AT.defaultChunkSize') to /dev/null
@@ -197,8 +196,8 @@ o_1_space_copy env =
197196 [ bgroup "copy"
198197 [ mkBench "FH.write . FH.read" env $ \inh _ ->
199198 writeRead inh (nullH env)
200− , mkBench "FH.writeWithBufferOf . FH.readWithBufferOf" env $ \inh _ ->
201− writeReadWithBufferOf inh (nullH env)
199+ , mkBench "FH.writeWith . FH.readWith" env $ \inh _ ->
200+ writeReadWith inh (nullH env)
202201 ]
203202 ]
204203
benchmark/Streamly/Benchmark/Prelude/Serial/Exceptions.hs+4−4
@@ -160,7 +160,7 @@ readWriteFinallyStream inh devNull =
160160fromToBytesBracket_Stream :: Handle -> Handle -> IO ()
161161fromToBytesBracket_Stream inh devNull =
162162 let readEx = IP.bracket_ (return ()) (\_ -> hClose inh)
163− (\_ -> IFH.toBytes inh)
163+ (\_ -> IFH.getBytes inh)
164164 in IFH.putBytes devNull $ readEx
165165
166166#ifdef INSPECTION
@@ -170,7 +170,7 @@ inspect $ hasNoTypeClasses 'fromToBytesBracket_Stream
170170fromToBytesBracketStream :: Handle -> Handle -> IO ()
171171fromToBytesBracketStream inh devNull =
172172 let readEx = S.bracket (return ()) (\_ -> hClose inh)
173− (\_ -> IFH.toBytes inh)
173+ (\_ -> IFH.getBytes inh)
174174 in IFH.putBytes devNull $ readEx
175175
176176readWriteBeforeAfterStream :: Handle -> Handle -> IO ()
@@ -280,7 +280,7 @@ toChunksBracket_ inh devNull =
280280 let readEx = IP.bracket_
281281 (return ())
282282 (\_ -> hClose inh)
283− (\_ -> IFH.toChunks inh)
283+ (\_ -> IFH.getChunks inh)
284284 in S.fold (IFH.writeChunks devNull) $ readEx
285285
286286#ifdef INSPECTION
@@ -292,7 +292,7 @@ toChunksBracket inh devNull =
292292 let readEx = S.bracket
293293 (return ())
294294 (\_ -> hClose inh)
295− (\_ -> IFH.toChunks inh)
295+ (\_ -> IFH.getChunks inh)
296296 in S.fold (IFH.writeChunks devNull) $ readEx
297297
298298o_1_space_copy_exceptions_toChunks :: BenchEnv -> [Benchmark]
benchmark/Streamly/Benchmark/Prelude/Serial/Split.hs+1−1
@@ -209,7 +209,7 @@ splitOnSeqUtf8 :: String -> Handle -> IO Int
209209splitOnSeqUtf8 str inh =
210210 (S.length $ IP.splitOnSeq (A.fromList str) FL.drain
211211 $ IUS.decodeUtf8Arrays
212− $ IFH.toChunks inh) -- >>= print
212+ $ IFH.getChunks inh) -- >>= print
213213
214214o_1_space_reduce_toChunks_split :: BenchEnv -> [Benchmark]
215215o_1_space_reduce_toChunks_split env =
benchmark/Streamly/Benchmark/Unicode/Stream.hs+1−1
@@ -55,7 +55,7 @@ copyCodecUtf8ArraysLenient inh outh =
5555 Stream.fold (Handle.write outh)
5656 $ Unicode.encodeUtf8'
5757 $ Unicode.decodeUtf8Arrays
58− $ Handle.toChunks inh
58+ $ Handle.getChunks inh
5959
6060#ifdef INSPECTION
6161inspect $ hasNoTypeClasses 'copyCodecUtf8ArraysLenient
src/Streamly/FileSystem/Handle.hs+9−3
@@ -76,9 +76,9 @@ module Streamly.FileSystem.Handle
7676 -- encountered.
7777
7878 , read
79− , readWithBufferOf
79+ , readWith
8080 , readChunks
81− , readChunksWithBufferOf
81+ , readChunksWith
8282
8383 -- ** Writing
8484 -- | 'TextEncoding', 'NewLineMode', and 'Buffering' options of the
@@ -87,8 +87,14 @@ module Streamly.FileSystem.Handle
8787 -- of the handle.
8888
8989 , write
90− , writeWithBufferOf
90+ , writeWith
9191 , writeChunks
92+
93+ -- * Deprecated
94+ , readChunksWithBufferOf
95+ , readWithBufferOf
96+ , writeChunksWithBufferOf
97+ , writeWithBufferOf
9298 )
9399where
94100
src/Streamly/Internal/Console/Stdio.hs+4−4
@@ -66,14 +66,14 @@ read = Unfold.lmap (\() -> stdin) Handle.read
6666
6767-- | Read a byte stream from standard input.
6868--
69−-- > getBytes = Handle.toBytes stdin
69+-- > getBytes = Handle.getBytes stdin
7070-- > getBytes = Stream.unfold Stdio.read ()
7171--
7272-- /Pre-release/
7373--
7474{-# INLINE getBytes #-}
7575getBytes :: MonadIO m => SerialT m Word8
76−getBytes = Handle.toBytes stdin
76+getBytes = Handle.getBytes stdin
7777
7878-- | Read a character stream from Utf8 encoded standard input.
7979--
@@ -96,14 +96,14 @@ readChunks = Unfold.lmap (\() -> stdin) Handle.readChunks
9696-- chunk is limited to @defaultChunkSize@. The actual size read may be less
9797-- than @defaultChunkSize@.
9898--
99−-- > getChunks = Handle.toChunks stdin
99+-- > getChunks = Handle.getChunks stdin
100100-- > getChunks = Stream.unfold Stdio.readChunks ()
101101--
102102-- /Pre-release/
103103--
104104{-# INLINE getChunks #-}
105105getChunks :: MonadIO m => SerialT m (Array Word8)
106−getChunks = Handle.toChunks stdin
106+getChunks = Handle.getChunks stdin
107107
108108{-
109109-- | Read UTF8 encoded lines from standard input.
src/Streamly/Internal/FileSystem/File.hs+39−37
@@ -44,7 +44,7 @@ module Streamly.Internal.FileSystem.File
4444 withFile
4545
4646 -- ** Read From File
47− , readWithBufferOf
47+ , readWith
4848 , read
4949 -- , readShared
5050 -- , readUtf8
@@ -54,11 +54,11 @@ module Streamly.Internal.FileSystem.File
5454 , toBytes
5555
5656 -- -- * Array Read
57− , readChunksWithBufferOf
57+ , readChunksWith
5858 , readChunksFromToWith
5959 , readChunks
6060
61− , toChunksWithBufferOf
61+ , toChunksWith
6262 , toChunks
6363
6464 -- ** Write To File
@@ -66,10 +66,10 @@ module Streamly.Internal.FileSystem.File
6666 -- , writeUtf8
6767 -- , writeUtf8ByLines
6868 -- , writeByFrames
69− , writeWithBufferOf
69+ , writeWith
7070
7171 , fromBytes
72− , fromBytesWithBufferOf
72+ , fromBytesWith
7373
7474 -- -- * Array Write
7575 , putChunk
@@ -78,7 +78,7 @@ module Streamly.Internal.FileSystem.File
7878
7979 -- ** Append To File
8080 , append
81− , appendWithBufferOf
81+ , appendWith
8282 -- , appendShared
8383 , appendArray
8484 , appendChunks
@@ -211,14 +211,16 @@ appendArray file arr = SIO.withFile file AppendMode (`FH.putChunk` arr)
211211-- Stream of Arrays IO
212212-------------------------------------------------------------------------------
213213
214−-- | @toChunksWithBufferOf size file@ reads a stream of arrays from file @file@.
214+-- | @toChunksWith size file@ reads a stream of arrays from file @file@.
215215-- The maximum size of a single array is specified by @size@. The actual size
216216-- read may be less than or equal to @size@.
217−{-# INLINE toChunksWithBufferOf #-}
218−toChunksWithBufferOf :: (IsStream t, MonadCatch m, MonadAsync m)
217+--
218+-- @since 0.9.0
219+{-# INLINE toChunksWith #-}
220+toChunksWith :: (IsStream t, MonadCatch m, MonadAsync m)
219221 => Int -> FilePath -> t m (Array Word8)
220−toChunksWithBufferOf size file =
221− withFile file ReadMode (FH.toChunksWithBufferOf size)
222+toChunksWith size file =
223+ withFile file ReadMode (FH.getChunksWith size)
222224
223225-- XXX read 'Array a' instead of Word8
224226--
@@ -226,13 +228,13 @@ toChunksWithBufferOf size file =
226228-- The maximum size of a single array is limited to @defaultChunkSize@. The
227229-- actual size read may be less than @defaultChunkSize@.
228230--
229−-- > toChunks = toChunksWithBufferOf defaultChunkSize
231+-- > toChunks = toChunksWith defaultChunkSize
230232--
231233-- @since 0.7.0
232234{-# INLINE toChunks #-}
233235toChunks :: (IsStream t, MonadCatch m, MonadAsync m)
234236 => FilePath -> t m (Array Word8)
235−toChunks = toChunksWithBufferOf defaultChunkSize
237+toChunks = toChunksWith defaultChunkSize
236238
237239-------------------------------------------------------------------------------
238240-- Read File to Stream
@@ -249,10 +251,10 @@ toChunks = toChunksWithBufferOf defaultChunkSize
249251--
250252-- /Pre-release/
251253--
252−{-# INLINE readChunksWithBufferOf #-}
253−readChunksWithBufferOf :: (MonadCatch m, MonadAsync m)
254+{-# INLINE readChunksWith #-}
255+readChunksWith :: (MonadCatch m, MonadAsync m)
254256 => Unfold m (Int, FilePath) (Array Word8)
255−readChunksWithBufferOf = usingFile2 FH.readChunksWithBufferOf
257+readChunksWith = usingFile2 FH.readChunksWith
256258
257259-- | Unfold the tuple @(from, to, bufsize, filepath)@ into a stream
258260-- of 'Word8' arrays.
@@ -282,9 +284,9 @@ readChunks = usingFile FH.readChunks
282284-- to the IO device are performed using buffers of @bufsize@.
283285--
284286-- /Pre-release/
285−{-# INLINE readWithBufferOf #-}
286−readWithBufferOf :: (MonadCatch m, MonadAsync m) => Unfold m (Int, FilePath) Word8
287−readWithBufferOf = usingFile2 FH.readWithBufferOf
287+{-# INLINE readWith #-}
288+readWith :: (MonadCatch m, MonadAsync m) => Unfold m (Int, FilePath) Word8
289+readWith = usingFile2 FH.readWith
288290
289291-- | Unfolds a file path into a byte stream. IO requests to the device are
290292-- performed in sizes of
@@ -303,7 +305,7 @@ read = UF.many A.read (usingFile FH.readChunks)
303305--
304306{-# INLINE toBytes #-}
305307toBytes :: (IsStream t, MonadCatch m, MonadAsync m) => FilePath -> t m Word8
306−toBytes file = AS.concat $ withFile file ReadMode FH.toChunks
308+toBytes file = AS.concat $ withFile file ReadMode FH.getChunks
307309
308310{-
309311-- | Generate a stream of elements of the given type from a file 'Handle'. The
@@ -346,13 +348,13 @@ fromChunks = fromChunksMode WriteMode
346348-- be written to the IO device as soon as we collect the specified number of
347349-- input elements.
348350--
349−-- @since 0.7.0
350−{-# INLINE fromBytesWithBufferOf #-}
351−fromBytesWithBufferOf :: (MonadAsync m, MonadCatch m)
351+-- @since 0.9.0
352+{-# INLINE fromBytesWith #-}
353+fromBytesWith :: (MonadAsync m, MonadCatch m)
352354 => Int -> FilePath -> SerialT m Word8 -> m ()
353−fromBytesWithBufferOf n file xs = fromChunks file $ AS.arraysOf n xs
355+fromBytesWith n file xs = fromChunks file $ AS.arraysOf n xs
354356
355−-- > write = 'writeWithBufferOf' defaultChunkSize
357+-- > write = 'writeWith' defaultChunkSize
356358--
357359-- | Write a byte stream to a file. Combines the bytes in chunks of size
358360-- up to 'A.defaultChunkSize' before writing. If the file exists it is
@@ -362,7 +364,7 @@ fromBytesWithBufferOf n file xs = fromChunks file $ AS.arraysOf n xs
362364-- /Pre-release/
363365{-# INLINE fromBytes #-}
364366fromBytes :: (MonadAsync m, MonadCatch m) => FilePath -> SerialT m Word8 -> m ()
365−fromBytes = fromBytesWithBufferOf defaultChunkSize
367+fromBytes = fromBytesWith defaultChunkSize
366368
367369{-
368370{-# INLINE write #-}
@@ -394,18 +396,18 @@ writeChunks path = Fold step initial extract
394396 FL.Partial fs -> extract1 fs
395397 FL.Done fb -> return fb
396398
397−-- | @writeWithBufferOf chunkSize handle@ writes the input stream to @handle@.
399+-- | @writeWith chunkSize handle@ writes the input stream to @handle@.
398400-- Bytes in the input stream are collected into a buffer until we have a chunk
399401-- of size @chunkSize@ and then written to the IO device.
400402--
401403-- /Pre-release/
402−{-# INLINE writeWithBufferOf #-}
403−writeWithBufferOf :: (MonadIO m, MonadCatch m)
404+{-# INLINE writeWith #-}
405+writeWith :: (MonadIO m, MonadCatch m)
404406 => Int -> FilePath -> Fold m Word8 ()
405−writeWithBufferOf n path =
407+writeWith n path =
406408 FL.chunksOf n (writeNUnsafe n) (writeChunks path)
407409
408−-- > write = 'writeWithBufferOf' A.defaultChunkSize
410+-- > write = 'writeWith' A.defaultChunkSize
409411--
410412-- | Write a byte stream to a file. Accumulates the input in chunks of up to
411413-- 'Streamly.Internal.Data.Array.Foreign.Type.defaultChunkSize' before writing to
@@ -415,7 +417,7 @@ writeWithBufferOf n path =
415417--
416418{-# INLINE write #-}
417419write :: (MonadIO m, MonadCatch m) => FilePath -> Fold m Word8 ()
418−write = writeWithBufferOf defaultChunkSize
420+write = writeWith defaultChunkSize
419421
420422-- | Append a stream of arrays to a file.
421423--
@@ -429,11 +431,11 @@ appendChunks = fromChunksMode AppendMode
429431-- be written to the IO device as soon as we collect the specified number of
430432-- input elements.
431433--
432−-- @since 0.7.0
433−{-# INLINE appendWithBufferOf #-}
434−appendWithBufferOf :: (MonadAsync m, MonadCatch m)
434+-- @since 0.9.0
435+{-# INLINE appendWith #-}
436+appendWith :: (MonadAsync m, MonadCatch m)
435437 => Int -> FilePath -> SerialT m Word8 -> m ()
436−appendWithBufferOf n file xs = appendChunks file $ AS.arraysOf n xs
438+appendWith n file xs = appendChunks file $ AS.arraysOf n xs
437439
438440-- | Append a byte stream to a file. Combines the bytes in chunks of size up to
439441-- 'A.defaultChunkSize' before writing. If the file exists then the new data
@@ -443,7 +445,7 @@ appendWithBufferOf n file xs = appendChunks file $ AS.arraysOf n xs
443445-- @since 0.7.0
444446{-# INLINE append #-}
445447append :: (MonadAsync m, MonadCatch m) => FilePath -> SerialT m Word8 -> m ()
446−append = appendWithBufferOf defaultChunkSize
448+append = appendWith defaultChunkSize
447449
448450{-
449451-- | Like 'append' but the file is not locked for exclusive writes.
src/Streamly/Internal/FileSystem/Handle.hs+117−93
@@ -11,13 +11,13 @@
1111--
1212-- The fundamental singleton IO APIs are 'getChunk' and 'putChunk' and the
1313-- fundamental stream IO APIs built on top of those are
14−-- 'readChunksWithBufferOf' and 'writeChunks'. Rest of this module is just
14+-- 'readChunksWith' and 'writeChunks'. Rest of this module is just
1515-- combinatorial programming using these.
1616--
1717-- We can achieve line buffering by folding lines in the input stream into a
1818-- stream of arrays using Stream.splitOn or Fold.takeEndBy_ and similar
1919-- operations. One can wrap the input stream in 'Maybe' type and then use
20−-- 'writeMaybesWithBufferOf' to achieve user controlled buffering.
20+-- 'writeMaybesWith' to achieve user controlled buffering.
2121
2222-- TODO: Need a separate module for pread/pwrite based reading writing for
2323-- seekable devices. Stateless read/write can be helpful in multithreaded
@@ -35,17 +35,17 @@ module Streamly.Internal.FileSystem.Handle
3535 -- , readUtf8
3636 -- , readLines
3737 -- , readFrames
38− , readWithBufferOf
38+ , readWith
3939
40− , toBytes
41− , toBytesWithBufferOf
40+ , getBytes
41+ , getBytesWith
4242
4343 -- * Chunked Stream Read
4444 , readChunks
45− , readChunksWithBufferOf
45+ , readChunksWith
4646
47− , toChunksWithBufferOf
48− , toChunks
47+ , getChunksWith
48+ , getChunks
4949
5050 -- * Byte Stream Write
5151 -- Byte stream write (Folds)
@@ -55,17 +55,17 @@ module Streamly.Internal.FileSystem.Handle
5555 -- , writeUtf8ByLines
5656 -- , writeByFrames
5757 -- , writeLines
58− , writeWithBufferOf
59− , writeMaybesWithBufferOf
58+ , writeWith
59+ , writeMaybesWith
6060
6161 , putBytes
62− , putBytesWithBufferOf
62+ , putBytesWith
6363
6464 -- * Chunked Stream Write
6565 , writeChunks
66− , writeChunksWithBufferOf
66+ , writeChunksWith
6767
68− , putChunksWithBufferOf
68+ , putChunksWith
6969 , putChunks
7070
7171 -- * Random Access (Seek)
@@ -101,6 +101,11 @@ module Streamly.Internal.FileSystem.Handle
101101 -- , writeChunksFromTo
102102 -- , writeChunksFromToWith
103103 -- , writeChunksFromThenToWith
104+ -- * Deprecated
105+ , readChunksWithBufferOf
106+ , readWithBufferOf
107+ , writeChunksWithBufferOf
108+ , writeWithBufferOf
104109 )
105110where
106111
@@ -203,13 +208,14 @@ getChunkOf = undefined
203208-- Stream of Arrays IO
204209-------------------------------------------------------------------------------
205210
206−-- | @toChunksWithBufferOf size h@ reads a stream of arrays from file handle @h@.
211+-- | @getChunksWith size h@ reads a stream of arrays from file handle @h@.
207212-- The maximum size of a single array is specified by @size@. The actual size
208213-- read may be less than or equal to @size@.
209−{-# INLINE _toChunksWithBufferOf #-}
210−_toChunksWithBufferOf :: (IsStream t, MonadIO m)
214+-- @since 0.9.0
215+{-# INLINE _getChunksWith #-}
216+_getChunksWith :: (IsStream t, MonadIO m)
211217 => Int -> Handle -> t m (Array Word8)
212−_toChunksWithBufferOf size h = go
218+_getChunksWith size h = go
213219 where
214220 -- XXX use cons/nil instead
215221 go = mkStream $ \_ yld _ stp -> do
@@ -218,22 +224,17 @@ _toChunksWithBufferOf size h = go
218224 then stp
219225 else yld arr go
220226
221−-- | @toChunksWithBufferOf size handle@ reads a stream of arrays from the file
227+-- | @getChunksWith size handle@ reads a stream of arrays from the file
222228-- handle @handle@. The maximum size of a single array is limited to @size@.
223229-- The actual size read may be less than or equal to @size@.
224230--
225−-- >>> toChunksWithBufferOf size h = Stream.unfold Handle.readChunksWithBufferOf (size, h)
231+-- >>> getChunksWith size h = Stream.unfold Handle.readChunksWith (size, h)
226232--
227−-- @since 0.7.0
228−{-# INLINE_NORMAL toChunksWithBufferOf #-}
229−toChunksWithBufferOf :: (IsStream t, MonadIO m) =>
233+-- @since 0.9.0
234+{-# INLINE_NORMAL getChunksWith #-}
235+getChunksWith :: (IsStream t, MonadIO m) =>
230236 Int -> Handle -> t m (Array Word8)
231−{-
232−toChunksWithBufferOf size h =
233− S.repeatM (getChunk size h)
234− & S.takeWhile ((/= 0) . byteLength)
235−-}
236−toChunksWithBufferOf size h = fromStreamD (D.Stream step ())
237+getChunksWith size h = fromStreamD (D.Stream step ())
237238 where
238239 {-# INLINE_LATE step #-}
239240 step _ _ = do
@@ -248,31 +249,27 @@ toChunksWithBufferOf size h = fromStreamD (D.Stream step ())
248249-- @bufsize@. The size of an array in the resulting stream is always less than
249250-- or equal to @bufsize@.
250251--
251−-- @since 0.7.0
252−{-# INLINE_NORMAL readChunksWithBufferOf #-}
253−readChunksWithBufferOf :: MonadIO m => Unfold m (Int, Handle) (Array Word8)
254−readChunksWithBufferOf =
252+-- @since 0.9.0
253+{-# INLINE_NORMAL readChunksWith #-}
254+readChunksWith :: MonadIO m => Unfold m (Int, Handle) (Array Word8)
255+readChunksWith =
255256 UF.lmap (uncurry getChunk) UF.repeatM
256257 & UF.takeWhile ((/= 0) . byteLength)
257−{-
258−readChunksWithBufferOf = Unfold step return
259258
260− where
261259
262− {-# INLINE_LATE step #-}
263− step (size, h) = do
264− arr <- getChunk size h
265− return $
266− case byteLength arr of
267− 0 -> D.Stop
268− _ -> D.Yield arr (size, h)
269−-}
260+-- | Same as 'readChunksWith'
261+--
262+-- @since 0.7.0
263+{-# DEPRECATED readChunksWithBufferOf "Please use readChunksWith instead." #-}
264+{-# INLINE_NORMAL readChunksWithBufferOf #-}
265+readChunksWithBufferOf :: MonadIO m => Unfold m (Int, Handle) (Array Word8)
266+readChunksWithBufferOf = readChunksWith
270267
271268-- There are two ways to implement this.
272269--
273−-- 1. Idiomatic: use a scan on the output of readChunksWithBufferOf to total
270+-- 1. Idiomatic: use a scan on the output of readChunksWith to total
274271-- the array lengths and trim the last array to correct size.
275−-- 2. Simply implement it from scratch like readChunksWithBufferOf.
272+-- 2. Simply implement it from scratch like readChunksWith.
276273--
277274-- XXX Change this to readChunksWithFromTo (bufferSize, from, to, h)?
278275--
@@ -305,19 +302,20 @@ readChunksFromToWith = Unfold step inject
305302 assert (len <= remaining)
306303 $ D.Yield arr (remaining - len, bufSize, h)
307304
305+
308306-- XXX read 'Array a' instead of Word8
309307--
310−-- | @toChunks handle@ reads a stream of arrays from the specified file
308+-- | @getChunks handle@ reads a stream of arrays from the specified file
311309-- handle. The maximum size of a single array is limited to
312310-- @defaultChunkSize@. The actual size read may be less than or equal to
313311-- @defaultChunkSize@.
314312--
315−-- >>> toChunks = Handle.toChunksWithBufferOf IO.defaultChunkSize
313+-- >>> getChunks = Handle.getChunksWith IO.defaultChunkSize
316314--
317−-- @since 0.7.0
318−{-# INLINE toChunks #-}
319−toChunks :: (IsStream t, MonadIO m) => Handle -> t m (Array Word8)
320−toChunks = toChunksWithBufferOf defaultChunkSize
315+-- @since 0.9.0
316+{-# INLINE getChunks #-}
317+getChunks :: (IsStream t, MonadIO m) => Handle -> t m (Array Word8)
318+getChunks = getChunksWith defaultChunkSize
321319
322320-- | Unfolds a handle into a stream of 'Word8' arrays. Requests to the IO
323321-- device are performed using a buffer of size
@@ -325,12 +323,12 @@ toChunks = toChunksWithBufferOf defaultChunkSize
325323-- size of arrays in the resulting stream are therefore less than or equal to
326324-- 'Streamly.Internal.Data.Array.Foreign.Type.defaultChunkSize'.
327325--
328−-- >>> readChunks = Unfold.supplyFirst IO.defaultChunkSize Handle.readChunksWithBufferOf
326+-- >>> readChunks = Unfold.supplyFirst IO.defaultChunkSize Handle.readChunksWith
329327--
330328-- @since 0.7.0
331329{-# INLINE readChunks #-}
332330readChunks :: MonadIO m => Unfold m Handle (Array Word8)
333−readChunks = UF.supplyFirst defaultChunkSize readChunksWithBufferOf
331+readChunks = UF.supplyFirst defaultChunkSize readChunksWith
334332
335333-------------------------------------------------------------------------------
336334-- Read File to Stream
@@ -343,22 +341,30 @@ readChunks = UF.supplyFirst defaultChunkSize readChunksWithBufferOf
343341-- | Unfolds the tuple @(bufsize, handle)@ into a byte stream, read requests
344342-- to the IO device are performed using buffers of @bufsize@.
345343--
346−-- >>> readWithBufferOf = Unfold.many Array.read Handle.readChunksWithBufferOf
344+-- >>> readWith = Unfold.many Array.read Handle.readChunksWith
345+--
346+-- @since 0.9.0
347+{-# INLINE readWith #-}
348+readWith :: MonadIO m => Unfold m (Int, Handle) Word8
349+readWith = UF.many A.read readChunksWith
350+
351+-- | Same as 'readWith'
347352--
348353-- @since 0.7.0
354+{-# DEPRECATED readWithBufferOf "Please use readWith instead." #-}
349355{-# INLINE readWithBufferOf #-}
350356readWithBufferOf :: MonadIO m => Unfold m (Int, Handle) Word8
351−readWithBufferOf = UF.many A.read readChunksWithBufferOf
357+readWithBufferOf = readWith
352358
353−-- | @toBytesWithBufferOf bufsize handle@ reads a byte stream from a file
359+-- | @getBytesWith bufsize handle@ reads a byte stream from a file
354360-- handle, reads are performed in chunks of up to @bufsize@.
355361--
356−-- >>> toBytesWithBufferOf size h = Stream.unfoldMany Array.read $ Handle.toChunksWithBufferOf size h
362+-- >>> getBytesWith size h = Stream.unfoldMany Array.read $ Handle.getChunksWith size h
357363--
358364-- /Pre-release/
359−{-# INLINE toBytesWithBufferOf #-}
360−toBytesWithBufferOf :: (IsStream t, MonadIO m) => Int -> Handle -> t m Word8
361−toBytesWithBufferOf size h = AS.concat $ toChunksWithBufferOf size h
365+{-# INLINE getBytesWith #-}
366+getBytesWith :: (IsStream t, MonadIO m) => Int -> Handle -> t m Word8
367+getBytesWith size h = AS.concat $ getChunksWith size h
362368
363369-- TODO
364370-- Generate a stream of elements of the given type from a file 'Handle'.
@@ -377,12 +383,12 @@ read = UF.many A.read readChunks
377383
378384-- | Generate a byte stream from a file 'Handle'.
379385--
380−-- >>> toBytes h = Stream.unfoldMany Array.read $ Handle.toChunks h
386+-- >>> getBytes h = Stream.unfoldMany Array.read $ Handle.getChunks h
381387--
382388-- /Pre-release/
383−{-# INLINE toBytes #-}
384−toBytes :: (IsStream t, MonadIO m) => Handle -> t m Word8
385−toBytes = AS.concat . toChunks
389+{-# INLINE getBytes #-}
390+getBytes :: (IsStream t, MonadIO m) => Handle -> t m Word8
391+getBytes = AS.concat . getChunks
386392
387393-------------------------------------------------------------------------------
388394-- Writing
@@ -427,28 +433,29 @@ putChunks h = S.mapM_ (putChunk h)
427433-- AS.concat is written in terms of foldMany. Once that is done we can write
428434-- idiomatic def in the docs.
429435--
430−-- | @putChunksWithBufferOf bufsize handle stream@ writes a stream of arrays
436+-- | @putChunksWith bufsize handle stream@ writes a stream of arrays
431437-- to @handle@ after coalescing the adjacent arrays in chunks of @bufsize@.
432438-- The chunk size is only a maximum and the actual writes could be smaller as
433439-- we do not split the arrays to fit exactly to the specified size.
434440--
435−-- @since 0.7.0
436−{-# INLINE putChunksWithBufferOf #-}
437−putChunksWithBufferOf :: (MonadIO m, Storable a)
441+-- @since 0.9.0
442+{-# INLINE putChunksWith #-}
443+putChunksWith :: (MonadIO m, Storable a)
438444 => Int -> Handle -> SerialT m (Array a) -> m ()
439−putChunksWithBufferOf n h xs = putChunks h $ AS.compact n xs
445+putChunksWith n h xs = putChunks h $ AS.compact n xs
440446
441−-- | @putBytesWithBufferOf bufsize handle stream@ writes @stream@ to @handle@
447+-- | @putBytesWith bufsize handle stream@ writes @stream@ to @handle@
442448-- in chunks of @bufsize@. A write is performed to the IO device as soon as we
443449-- collect the required input size.
444450--
445−-- >>> putBytesWithBufferOf n h m = Handle.putChunks h $ Stream.arraysOf n m
451+-- >>> putBytesWith n h m = Handle.putChunks h $ Stream.arraysOf n m
446452--
447−-- @since 0.7.0
448−{-# INLINE putBytesWithBufferOf #-}
449−putBytesWithBufferOf :: MonadIO m => Int -> Handle -> SerialT m Word8 -> m ()
450−putBytesWithBufferOf n h m = putChunks h $ S.arraysOf n m
451−-- putBytesWithBufferOf n h m = putChunks h $ AS.arraysOf n m
453+-- @since 0.9.0
454+{-# INLINE putBytesWith #-}
455+putBytesWith :: MonadIO m => Int -> Handle -> SerialT m Word8 -> m ()
456+putBytesWith n h m = putChunks h $ S.arraysOf n m
457+
458+-- putBytesWith n h m = putChunks h $ AS.arraysOf n m
452459
453460-- | Write a byte stream to a file handle. Accumulates the input in chunks of
454461-- up to 'Streamly.Internal.Data.Array.Foreign.Type.defaultChunkSize' before writing.
@@ -456,12 +463,12 @@ putBytesWithBufferOf n h m = putChunks h $ S.arraysOf n m
456463-- NOTE: This may perform better than the 'write' fold, you can try this if you
457464-- need some extra perf boost.
458465--
459−-- >>> putBytes = Handle.putBytesWithBufferOf IO.defaultChunkSize
466+-- >>> putBytes = Handle.putBytesWith IO.defaultChunkSize
460467--
461468-- @since 0.7.0
462469{-# INLINE putBytes #-}
463470putBytes :: MonadIO m => Handle -> SerialT m Word8 -> m ()
464−putBytes = putBytesWithBufferOf defaultChunkSize
471+putBytes = putBytesWith defaultChunkSize
465472
466473-- | Write a stream of arrays to a handle. Each array in the stream is written
467474-- to the device as a separate IO request.
@@ -482,17 +489,26 @@ consumeChunks = Refold.drainBy putChunk
482489
483490-- XXX lpackArraysChunksOf should be written idiomatically
484491--
485−-- | @writeChunksWithBufferOf bufsize handle@ writes a stream of arrays
492+-- | @writeChunksWith bufsize handle@ writes a stream of arrays
486493-- to @handle@ after coalescing the adjacent arrays in chunks of @bufsize@.
487494-- We never split an array, if a single array is bigger than the specified size
488495-- it emitted as it is. Multiple arrays are coalesed as long as the total size
489496-- remains below the specified size.
490497--
498+-- @since 0.9.0
499+{-# INLINE writeChunksWith #-}
500+writeChunksWith :: (MonadIO m, Storable a)
501+ => Int -> Handle -> Fold m (Array a) ()
502+writeChunksWith n h = lpackArraysChunksOf n (writeChunks h)
503+
504+-- | Same as 'writeChunksWith'
505+--
491506-- @since 0.7.0
507+{-# DEPRECATED writeChunksWithBufferOf "Please use writeChunksWith instead." #-}
492508{-# INLINE writeChunksWithBufferOf #-}
493509writeChunksWithBufferOf :: (MonadIO m, Storable a)
494510 => Int -> Handle -> Fold m (Array a) ()
495−writeChunksWithBufferOf n h = lpackArraysChunksOf n (writeChunks h)
511+writeChunksWithBufferOf = writeChunksWith
496512
497513-- GHC buffer size dEFAULT_FD_BUFFER_SIZE=8192 bytes.
498514--
@@ -504,55 +520,63 @@ writeChunksWithBufferOf n h = lpackArraysChunksOf n (writeChunks h)
504520
505521-- XXX Maybe we should have a Fold.arraysOf like we have Stream.arraysOf
506522--
507−-- | @writeWithBufferOf reqSize handle@ writes the input stream to @handle@.
523+-- | @writeWith reqSize handle@ writes the input stream to @handle@.
508524-- Bytes in the input stream are collected into a buffer until we have a chunk
509525-- of @reqSize@ and then written to the IO device.
510526--
511−-- >>> writeWithBufferOf n h = Fold.chunksOf n (Array.writeNUnsafe n) (Handle.writeChunks h)
527+-- >>> writeWith n h = Fold.chunksOf n (Array.writeNUnsafe n) (Handle.writeChunks h)
528+--
529+-- @since 0.7.0
530+{-# INLINE writeWith #-}
531+writeWith :: MonadIO m => Int -> Handle -> Fold m Word8 ()
532+writeWith n h = FL.chunksOf n (writeNUnsafe n) (writeChunks h)
533+
534+-- | Same as 'writeWith'
512535--
513536-- @since 0.7.0
537+{-# DEPRECATED writeWithBufferOf "Please use writeWith instead." #-}
514538{-# INLINE writeWithBufferOf #-}
515539writeWithBufferOf :: MonadIO m => Int -> Handle -> Fold m Word8 ()
516−writeWithBufferOf n h = FL.chunksOf n (writeNUnsafe n) (writeChunks h)
540+writeWithBufferOf = writeWith
517541
518542-- | Write a stream of 'Maybe' values. Keep buffering the just values in an
519543-- array until a 'Nothing' is encountered or the buffer size exceeds the
520544-- specified limit, at that point flush the buffer to the handle.
521545--
522546-- /Pre-release/
523−{-# INLINE writeMaybesWithBufferOf #-}
524−writeMaybesWithBufferOf :: (MonadIO m )
547+{-# INLINE writeMaybesWith #-}
548+writeMaybesWith :: (MonadIO m )
525549 => Int -> Handle -> Fold m (Maybe Word8) ()
526−writeMaybesWithBufferOf n h =
550+writeMaybesWith n h =
527551 let writeNJusts = FL.lmap fromJust $ A.writeN n
528552 writeOnNothing = FL.takeEndBy_ isNothing writeNJusts
529553 in FL.many writeOnNothing (writeChunks h)
530554
531−-- | Like 'writeWithBufferOf' but uses the experimental 'Refold' API.
555+-- | Like 'writeWith' but uses the experimental 'Refold' API.
532556--
533557-- /Internal/
534−{-# INLINE consumerWithBufferOf #-}
535−consumerWithBufferOf :: MonadIO m => Int -> Refold m Handle Word8 ()
536−consumerWithBufferOf n =
558+{-# INLINE consumerWith #-}
559+consumerWith :: MonadIO m => Int -> Refold m Handle Word8 ()
560+consumerWith n =
537561 FL.refoldMany (FL.take n $ writeNUnsafe n) consumeChunks
538562
539563-- | Write a byte stream to a file handle. Accumulates the input in chunks of
540564-- up to 'Streamly.Internal.Data.Array.Foreign.Type.defaultChunkSize' before writing
541565-- to the IO device.
542566--
543−-- >>> write = Handle.writeWithBufferOf IO.defaultChunkSize
567+-- >>> write = Handle.writeWith IO.defaultChunkSize
544568--
545569-- @since 0.7.0
546570{-# INLINE write #-}
547571write :: MonadIO m => Handle -> Fold m Word8 ()
548−write = writeWithBufferOf defaultChunkSize
572+write = writeWith defaultChunkSize
549573
550574-- | Like 'write' but uses the experimental 'Refold' API.
551575--
552576-- /Internal/
553577{-# INLINE consumer #-}
554578consumer :: MonadIO m => Refold m Handle Word8 ()
555−consumer = consumerWithBufferOf defaultChunkSize
579+consumer = consumerWith defaultChunkSize
556580
557581{-
558582{-# INLINE write #-}
test/Streamly/Test/FileSystem/Handle.hs+7−7
@@ -80,7 +80,7 @@ readFromHandle =
8080readWithBufferFromHandle :: IO (SerialT IO Char)
8181readWithBufferFromHandle =
8282 let f1 = (\h -> (1024, h))
83− f2 = Unicode.decodeUtf8 . Stream.unfold Handle.readWithBufferOf . f1
83+ f2 = Unicode.decodeUtf8 . Stream.unfold Handle.readWith . f1
8484 in executor f2
8585
8686readChunksFromHandle :: IO (SerialT IO Char)
@@ -96,7 +96,7 @@ readChunksWithBuffer =
9696 f2 =
9797 Unicode.decodeUtf8
9898 . Stream.concatMap Array.toStream
99− . Stream.unfold Handle.readChunksWithBufferOf
99+ . Stream.unfold Handle.readChunksWith
100100 . f1
101101 in executor f2
102102
@@ -148,7 +148,7 @@ testWriteWithChunk =
148148 hw <- openFile fpathWrite ReadWriteMode
149149 hSeek hw AbsoluteSeek 0
150150 _ <- Stream.fold (Handle.writeChunks hw)
151− $ Stream.unfold Handle.readChunksWithBufferOf (1024, hr)
151+ $ Stream.unfold Handle.readChunksWith (1024, hr)
152152 hFlush hw
153153 hSeek hw AbsoluteSeek 0
154154 ls <- Stream.toList $ Stream.unfold Handle.read hw
@@ -209,9 +209,9 @@ main =
209209 describe moduleName $ do
210210 describe "Read From Handle" $ do
211211 prop "read" $ testRead readFromHandle
212− prop "readWithBufferOf" $ testRead readWithBufferFromHandle
212+ prop "readWith" $ testRead readWithBufferFromHandle
213213 prop "readChunks" $ testRead readChunksFromHandle
214− prop "readChunksWithBufferOf" $ testRead readChunksWithBuffer
214+ prop "readChunksWith" $ testRead readChunksWithBuffer
215215 prop "readChunksFromToWith (0,0,n)"
216216 testReadChunksFromToWithFirstByte
217217 prop "readChunksFromToWith (1,1,n)"
@@ -226,7 +226,7 @@ main =
226226 testReadChunksFromToWithRangeInvalid
227227 describe "Write To Handle" $ do
228228 prop "write" $ testWrite Handle.write
229− prop "writeWithBufferOf"
230− $ testWrite $ Handle.writeWithBufferOf 1024
229+ prop "writeWith"
230+ $ testWrite $ Handle.writeWith 1024
231231 -- XXX This test needs a lot of stack when built with -O0
232232 prop "writeChunks" testWriteWithChunk