on master help sign in
Move FileSystem.File module to streamly-core
dfcb6e5Harendra Kumar
src/Streamly/Internal/FileSystem/File.hs → core/src/Streamly/Internal/FileSystem/File.hsrenamed+26−27
@@ -104,7 +104,6 @@ import qualified Control.Monad.Catch as MC
104import qualified System.IO as SIO
104import qualified System.IO as SIO
105
105
106import Streamly.Data.Fold (chunksOf, drain)
106import Streamly.Data.Fold (chunksOf, drain)
107−import Streamly.Internal.Control.Concurrent (MonadAsync)
108import Streamly.Internal.Data.Array.Unboxed.Type (Array(..), writeNUnsafe)
107import Streamly.Internal.Data.Array.Unboxed.Type (Array(..), writeNUnsafe)
109import Streamly.Internal.Data.Fold.Type (Fold(..))
108import Streamly.Internal.Data.Fold.Type (Fold(..))
110import Streamly.Data.Stream (Stream)
109import Streamly.Data.Stream (Stream)
@@ -148,7 +147,7 @@ import qualified Streamly.Data.Stream as S (fold, bracketIO, mapM)
148-- /Pre-release/
147-- /Pre-release/
149--
148--
150{-# INLINE withFile #-}
149{-# INLINE withFile #-}
151−withFile :: (MonadCatch m, MonadAsync m)
150+withFile :: (MonadCatch m, MonadIO m)
152 => FilePath -> IOMode -> (Handle -> Stream m a) -> Stream m a
151 => FilePath -> IOMode -> (Handle -> Stream m a) -> Stream m a
153withFile file mode = S.bracketIO (openFile file mode) hClose
152withFile file mode = S.bracketIO (openFile file mode) hClose
154
153
@@ -161,12 +160,12 @@ withFile file mode = S.bracketIO (openFile file mode) hClose
161-- /Pre-release/
160-- /Pre-release/
162--
161--
163{-# INLINE usingFile #-}
162{-# INLINE usingFile #-}
164−usingFile :: (MonadCatch m, MonadAsync m)
163+usingFile :: (MonadCatch m, MonadIO m)
165 => Unfold m Handle a -> Unfold m FilePath a
164 => Unfold m Handle a -> Unfold m FilePath a
166usingFile = UF.bracketIO (`openFile` ReadMode) hClose
165usingFile = UF.bracketIO (`openFile` ReadMode) hClose
167
166
168{-# INLINE usingFile2 #-}
167{-# INLINE usingFile2 #-}
169−usingFile2 :: (MonadCatch m, MonadAsync m)
168+usingFile2 :: (MonadCatch m, MonadIO m)
170 => Unfold m (x, Handle) a -> Unfold m (x, FilePath) a
169 => Unfold m (x, Handle) a -> Unfold m (x, FilePath) a
171usingFile2 = UF.bracketIO before after
170usingFile2 = UF.bracketIO before after
172
171
@@ -179,7 +178,7 @@ usingFile2 = UF.bracketIO before after
179 after (_, h) = hClose h
178 after (_, h) = hClose h
180
179
181{-# INLINE usingFile3 #-}
180{-# INLINE usingFile3 #-}
182−usingFile3 :: (MonadCatch m, MonadAsync m)
181+usingFile3 :: (MonadCatch m, MonadIO m)
183 => Unfold m (x, y, z, Handle) a -> Unfold m (x, y, z, FilePath) a
182 => Unfold m (x, y, z, Handle) a -> Unfold m (x, y, z, FilePath) a
184usingFile3 = UF.bracketIO before after
183usingFile3 = UF.bracketIO before after
185
184
@@ -225,14 +224,14 @@ appendArray file arr = SIO.withFile file AppendMode (`FH.putChunk` arr)
225--
224--
226-- @since 0.9.0
225-- @since 0.9.0
227{-# INLINE readChunksWith #-}
226{-# INLINE readChunksWith #-}
228−readChunksWith :: (MonadCatch m, MonadAsync m)
227+readChunksWith :: (MonadCatch m, MonadIO m)
229 => Int -> FilePath -> Stream m (Array Word8)
228 => Int -> FilePath -> Stream m (Array Word8)
230readChunksWith size file =
229readChunksWith size file =
231 withFile file ReadMode (FH.readChunksWith size)
230 withFile file ReadMode (FH.readChunksWith size)
232
231
233{-# DEPRECATED toChunksWithBufferOf "Please use 'readChunksWith' instead" #-}
232{-# DEPRECATED toChunksWithBufferOf "Please use 'readChunksWith' instead" #-}
234{-# INLINE toChunksWithBufferOf #-}
233{-# INLINE toChunksWithBufferOf #-}
235−toChunksWithBufferOf :: (MonadCatch m, MonadAsync m)
234+toChunksWithBufferOf :: (MonadCatch m, MonadIO m)
236 => Int -> FilePath -> Stream m (Array Word8)
235 => Int -> FilePath -> Stream m (Array Word8)
237toChunksWithBufferOf = readChunksWith
236toChunksWithBufferOf = readChunksWith
238
237
@@ -246,13 +245,13 @@ toChunksWithBufferOf = readChunksWith
246--
245--
247-- @since 0.7.0
246-- @since 0.7.0
248{-# INLINE readChunks #-}
247{-# INLINE readChunks #-}
249−readChunks :: (MonadCatch m, MonadAsync m)
248+readChunks :: (MonadCatch m, MonadIO m)
250 => FilePath -> Stream m (Array Word8)
249 => FilePath -> Stream m (Array Word8)
251readChunks = readChunksWith defaultChunkSize
250readChunks = readChunksWith defaultChunkSize
252
251
253{-# DEPRECATED toChunks "Please use 'readChunks' instead" #-}
252{-# DEPRECATED toChunks "Please use 'readChunks' instead" #-}
254{-# INLINE toChunks #-}
253{-# INLINE toChunks #-}
255−toChunks :: (MonadCatch m, MonadAsync m) => FilePath -> Stream m (Array Word8)
254+toChunks :: (MonadCatch m, MonadIO m) => FilePath -> Stream m (Array Word8)
256toChunks = readChunks
255toChunks = readChunks
257
256
258-------------------------------------------------------------------------------
257-------------------------------------------------------------------------------
@@ -271,14 +270,14 @@ toChunks = readChunks
271-- /Pre-release/
270-- /Pre-release/
272--
271--
273{-# INLINE chunkReaderWith #-}
272{-# INLINE chunkReaderWith #-}
274−chunkReaderWith :: (MonadCatch m, MonadAsync m)
273+chunkReaderWith :: (MonadCatch m, MonadIO m)
275 => Unfold m (Int, FilePath) (Array Word8)
274 => Unfold m (Int, FilePath) (Array Word8)
276chunkReaderWith = usingFile2 FH.chunkReaderWith
275chunkReaderWith = usingFile2 FH.chunkReaderWith
277
276
278{-# DEPRECATED readChunksWithBufferOf
277{-# DEPRECATED readChunksWithBufferOf
279 "Please use 'chunkReaderWith' instead" #-}
278 "Please use 'chunkReaderWith' instead" #-}
280{-# INLINE readChunksWithBufferOf #-}
279{-# INLINE readChunksWithBufferOf #-}
281−readChunksWithBufferOf :: (MonadCatch m, MonadAsync m)
280+readChunksWithBufferOf :: (MonadCatch m, MonadIO m)
282 => Unfold m (Int, FilePath) (Array Word8)
281 => Unfold m (Int, FilePath) (Array Word8)
283readChunksWithBufferOf = chunkReaderWith
282readChunksWithBufferOf = chunkReaderWith
284
283
@@ -291,14 +290,14 @@ readChunksWithBufferOf = chunkReaderWith
291--
290--
292-- /Pre-release/
291-- /Pre-release/
293{-# INLINE chunkReaderFromToWith #-}
292{-# INLINE chunkReaderFromToWith #-}
294−chunkReaderFromToWith :: (MonadCatch m, MonadAsync m) =>
293+chunkReaderFromToWith :: (MonadCatch m, MonadIO m) =>
295 Unfold m (Int, Int, Int, FilePath) (Array Word8)
294 Unfold m (Int, Int, Int, FilePath) (Array Word8)
296chunkReaderFromToWith = usingFile3 FH.chunkReaderFromToWith
295chunkReaderFromToWith = usingFile3 FH.chunkReaderFromToWith
297
296
298{-# DEPRECATED readChunksFromToWith
297{-# DEPRECATED readChunksFromToWith
299 "Please use 'chunkReaderFromToWith' instead" #-}
298 "Please use 'chunkReaderFromToWith' instead" #-}
300{-# INLINE readChunksFromToWith #-}
299{-# INLINE readChunksFromToWith #-}
301−readChunksFromToWith :: (MonadCatch m, MonadAsync m) =>
300+readChunksFromToWith :: (MonadCatch m, MonadIO m) =>
302 Unfold m (Int, Int, Int, FilePath) (Array Word8)
301 Unfold m (Int, Int, Int, FilePath) (Array Word8)
303readChunksFromToWith = chunkReaderFromToWith
302readChunksFromToWith = chunkReaderFromToWith
304
303
@@ -310,7 +309,7 @@ readChunksFromToWith = chunkReaderFromToWith
310--
309--
311-- /Pre-release/
310-- /Pre-release/
312{-# INLINE chunkReader #-}
311{-# INLINE chunkReader #-}
313−chunkReader :: (MonadCatch m, MonadAsync m) => Unfold m FilePath (Array Word8)
312+chunkReader :: (MonadCatch m, MonadIO m) => Unfold m FilePath (Array Word8)
314chunkReader = usingFile FH.chunkReader
313chunkReader = usingFile FH.chunkReader
315
314
316-- | Unfolds the tuple @(bufsize, filepath)@ into a byte stream, read requests
315-- | Unfolds the tuple @(bufsize, filepath)@ into a byte stream, read requests
@@ -318,12 +317,12 @@ chunkReader = usingFile FH.chunkReader
318--
317--
319-- /Pre-release/
318-- /Pre-release/
320{-# INLINE readerWith #-}
319{-# INLINE readerWith #-}
321−readerWith :: (MonadCatch m, MonadAsync m) => Unfold m (Int, FilePath) Word8
320+readerWith :: (MonadCatch m, MonadIO m) => Unfold m (Int, FilePath) Word8
322readerWith = usingFile2 FH.readerWith
321readerWith = usingFile2 FH.readerWith
323
322
324{-# DEPRECATED readWithBufferOf "Please use 'readerWith' instead" #-}
323{-# DEPRECATED readWithBufferOf "Please use 'readerWith' instead" #-}
325{-# INLINE readWithBufferOf #-}
324{-# INLINE readWithBufferOf #-}
326−readWithBufferOf :: (MonadCatch m, MonadAsync m) =>
325+readWithBufferOf :: (MonadCatch m, MonadIO m) =>
327 Unfold m (Int, FilePath) Word8
326 Unfold m (Int, FilePath) Word8
328readWithBufferOf = readerWith
327readWithBufferOf = readerWith
329
328
@@ -333,7 +332,7 @@ readWithBufferOf = readerWith
333--
332--
334-- /Pre-release/
333-- /Pre-release/
335{-# INLINE reader #-}
334{-# INLINE reader #-}
336−reader :: (MonadCatch m, MonadAsync m) => Unfold m FilePath Word8
335+reader :: (MonadCatch m, MonadIO m) => Unfold m FilePath Word8
337reader = UF.many A.reader (usingFile FH.chunkReader)
336reader = UF.many A.reader (usingFile FH.chunkReader)
338
337
339-- | Generate a stream of bytes from a file specified by path. The stream ends
338-- | Generate a stream of bytes from a file specified by path. The stream ends
@@ -343,12 +342,12 @@ reader = UF.many A.reader (usingFile FH.chunkReader)
343-- /Pre-release/
342-- /Pre-release/
344--
343--
345{-# INLINE read #-}
344{-# INLINE read #-}
346−read :: (MonadCatch m, MonadAsync m) => FilePath -> Stream m Word8
345+read :: (MonadCatch m, MonadIO m) => FilePath -> Stream m Word8
347read file = AS.concat $ withFile file ReadMode FH.readChunks
346read file = AS.concat $ withFile file ReadMode FH.readChunks
348
347
349{-# DEPRECATED toBytes "Please use 'read' instead" #-}
348{-# DEPRECATED toBytes "Please use 'read' instead" #-}
350{-# INLINE toBytes #-}
349{-# INLINE toBytes #-}
351−toBytes :: (MonadCatch m, MonadAsync m) => FilePath -> Stream m Word8
350+toBytes :: (MonadCatch m, MonadIO m) => FilePath -> Stream m Word8
352toBytes = read
351toBytes = read
353
352
354{-
353{-
@@ -367,7 +366,7 @@ readShared = undefined
367-------------------------------------------------------------------------------
366-------------------------------------------------------------------------------
368
367
369{-# INLINE fromChunksMode #-}
368{-# INLINE fromChunksMode #-}
370−fromChunksMode :: (MonadAsync m, MonadCatch m)
369+fromChunksMode :: (MonadIO m, MonadCatch m)
371 => IOMode -> FilePath -> Stream m (Array a) -> m ()
370 => IOMode -> FilePath -> Stream m (Array a) -> m ()
372fromChunksMode mode file xs = S.fold drain $
371fromChunksMode mode file xs = S.fold drain $
373 withFile file mode (\h -> S.mapM (FH.putChunk h) xs)
372 withFile file mode (\h -> S.mapM (FH.putChunk h) xs)
@@ -376,7 +375,7 @@ fromChunksMode mode file xs = S.fold drain $
376--
375--
377-- @since 0.7.0
376-- @since 0.7.0
378{-# INLINE fromChunks #-}
377{-# INLINE fromChunks #-}
379−fromChunks :: (MonadAsync m, MonadCatch m)
378+fromChunks :: (MonadIO m, MonadCatch m)
380 => FilePath -> Stream m (Array a) -> m ()
379 => FilePath -> Stream m (Array a) -> m ()
381fromChunks = fromChunksMode WriteMode
380fromChunks = fromChunksMode WriteMode
382
381
@@ -394,13 +393,13 @@ fromChunks = fromChunksMode WriteMode
394--
393--
395-- @since 0.9.0
394-- @since 0.9.0
396{-# INLINE fromBytesWith #-}
395{-# INLINE fromBytesWith #-}
397−fromBytesWith :: (MonadAsync m, MonadCatch m)
396+fromBytesWith :: (MonadIO m, MonadCatch m)
398 => Int -> FilePath -> Stream m Word8 -> m ()
397 => Int -> FilePath -> Stream m Word8 -> m ()
399fromBytesWith n file xs = fromChunks file $ AS.arraysOf n xs
398fromBytesWith n file xs = fromChunks file $ AS.arraysOf n xs
400
399
401{-# DEPRECATED fromBytesWithBufferOf "Please use 'fromBytesWith' instead" #-}
400{-# DEPRECATED fromBytesWithBufferOf "Please use 'fromBytesWith' instead" #-}
402{-# INLINE fromBytesWithBufferOf #-}
401{-# INLINE fromBytesWithBufferOf #-}
403−fromBytesWithBufferOf :: (MonadAsync m, MonadCatch m)
402+fromBytesWithBufferOf :: (MonadIO m, MonadCatch m)
404 => Int -> FilePath -> Stream m Word8 -> m ()
403 => Int -> FilePath -> Stream m Word8 -> m ()
405fromBytesWithBufferOf = fromBytesWith
404fromBytesWithBufferOf = fromBytesWith
406
405
@@ -413,7 +412,7 @@ fromBytesWithBufferOf = fromBytesWith
413--
412--
414-- /Pre-release/
413-- /Pre-release/
415{-# INLINE fromBytes #-}
414{-# INLINE fromBytes #-}
416−fromBytes :: (MonadAsync m, MonadCatch m) => FilePath -> Stream m Word8 -> m ()
415+fromBytes :: (MonadIO m, MonadCatch m) => FilePath -> Stream m Word8 -> m ()
417fromBytes = fromBytesWith defaultChunkSize
416fromBytes = fromBytesWith defaultChunkSize
418
417
419{-
418{-
@@ -479,7 +478,7 @@ write = writeWith defaultChunkSize
479--
478--
480-- @since 0.7.0
479-- @since 0.7.0
481{-# INLINE appendChunks #-}
480{-# INLINE appendChunks #-}
482−appendChunks :: (MonadAsync m, MonadCatch m)
481+appendChunks :: (MonadIO m, MonadCatch m)
483 => FilePath -> Stream m (Array a) -> m ()
482 => FilePath -> Stream m (Array a) -> m ()
484appendChunks = fromChunksMode AppendMode
483appendChunks = fromChunksMode AppendMode
485
484
@@ -489,7 +488,7 @@ appendChunks = fromChunksMode AppendMode
489--
488--
490-- @since 0.9.0
489-- @since 0.9.0
491{-# INLINE appendWith #-}
490{-# INLINE appendWith #-}
492−appendWith :: (MonadAsync m, MonadCatch m)
491+appendWith :: (MonadIO m, MonadCatch m)
493 => Int -> FilePath -> Stream m Word8 -> m ()
492 => Int -> FilePath -> Stream m Word8 -> m ()
494appendWith n file xs = appendChunks file $ AS.arraysOf n xs
493appendWith n file xs = appendChunks file $ AS.arraysOf n xs
495
494
@@ -500,7 +499,7 @@ appendWith n file xs = appendChunks file $ AS.arraysOf n xs
500--
499--
501-- @since 0.7.0
500-- @since 0.7.0
502{-# INLINE append #-}
501{-# INLINE append #-}
503−append :: (MonadAsync m, MonadCatch m) => FilePath -> Stream m Word8 -> m ()
502+append :: (MonadIO m, MonadCatch m) => FilePath -> Stream m Word8 -> m ()
504append = appendWith defaultChunkSize
503append = appendWith defaultChunkSize
505
504
506{-
505{-
core/streamly-core.cabal+1
@@ -335,6 +335,7 @@ library
335
335
336 -- Filesystem/IO
336 -- Filesystem/IO
337 , Streamly.Internal.FileSystem.Handle
337 , Streamly.Internal.FileSystem.Handle
338+ , Streamly.Internal.FileSystem.File
338
339
339 -- Ring Arrays
340 -- Ring Arrays
340 , Streamly.Internal.Data.Ring.Unboxed
341 , Streamly.Internal.Data.Ring.Unboxed
streamly.cabal−1
@@ -371,7 +371,6 @@ library
371
371
372 -- streamly-filesystem
372 -- streamly-filesystem
373 , Streamly.Internal.FileSystem.Dir
373 , Streamly.Internal.FileSystem.Dir
374− , Streamly.Internal.FileSystem.File
375
374
376 -- streamly-network
375 -- streamly-network
377 , Streamly.Internal.Network.Socket
376 , Streamly.Internal.Network.Socket