on fe28607 help sign in
666 lines 24 kB history raw
1#include "inline.hs"
3-- |
4-- Module : Streamly.Internal.FileSystem.File
5-- Copyright : (c) 2019 Composewell Technologies
6--
7-- License : BSD3
8-- Maintainer : streamly@composewell.com
9-- Stability : pre-release
10-- Portability : GHC
11--
12-- Read and write streams and arrays to and from files specified by their paths
13-- in the file system. Unlike the handle based APIs which can have a read/write
14-- session consisting of multiple reads and writes to the handle, these APIs
15-- are one shot read or write APIs. These APIs open the file handle, perform
16-- the requested operation and close the handle. Thease are safer compared to
17-- the handle based APIs as there is no possibility of a file descriptor
18-- leakage.
19--
20-- > import qualified Streamly.Internal.FileSystem.File as File
21--
23module Streamly.Internal.FileSystem.File
24 (
25 -- * Streaming IO
26 -- | Stream data to or from a file or device sequentially. When reading,
27 -- the stream is lazy and generated on-demand as the consumer consumes it.
28 -- Read IO requests to the IO device are performed in chunks limited to a
29 -- maximum size of 32KiB, this is referred to as @defaultChunkSize@ in the
30 -- documentation. One IO request may or may not read the full
31 -- chunk. If the whole stream is not consumed, it is possible that we may
32 -- read slightly more from the IO device than what the consumer needed.
33 -- Unless specified otherwise in the API, writes are collected into chunks
34 -- of @defaultChunkSize@ before they are written to the IO device.
36 -- Streaming APIs work for all kind of devices, seekable or non-seekable;
37 -- including disks, files, memory devices, terminals, pipes, sockets and
38 -- fifos. While random access APIs work only for files or devices that have
39 -- random access or seek capability for example disks, memory devices.
40 -- Devices like terminals, pipes, sockets and fifos do not have random
41 -- access capability.
43 -- ** File IO Using Handle
44 withFile
46 -- ** Streams
47 , read
48 , readChunksWith
49 , readChunks
51 -- ** Unfolds
52 , readerWith
53 , reader
54 -- , readShared
55 -- , readUtf8
56 -- , readLines
57 -- , readFrames
58 , chunkReaderWith
59 , chunkReaderFromToWith
60 , chunkReader
62 -- ** Write To File
63 , putChunk -- writeChunk?
65 -- ** Folds
66 , write
67 -- , writeUtf8
68 -- , writeUtf8ByLines
69 -- , writeByFrames
70 , writeWith
71 , writeChunks
73 -- ** Writing Streams
74 , fromBytes -- putBytes?
75 , fromBytesWith
76 , fromChunks
78 -- ** Append To File
79 , append
80 , appendWith
81 -- , appendShared
82 , appendArray
83 , appendChunks
85 -- * Deprecated
86 , readWithBufferOf
87 , readChunksWithBufferOf
88 , readChunksFromToWith
89 , toBytes
90 , toChunks
91 , toChunksWithBufferOf
92 , writeWithBufferOf
93 , fromBytesWithBufferOf
94 )
95where
97import Control.Monad.Catch (MonadCatch)
98import Control.Monad.IO.Class (MonadIO(..))
99import Data.Word (Word8)
100import System.IO (Handle, openFile, IOMode(..), hClose)
101import Prelude hiding (read)
103import qualified Control.Monad.Catch as MC
104import qualified System.IO as SIO
106import Streamly.Data.Fold (chunksOf, drain)
107import Streamly.Internal.Data.Array.Type (Array(..), writeNUnsafe)
108import Streamly.Internal.Data.Fold.Type (Fold(..))
109import Streamly.Data.Stream (Stream)
110import Streamly.Internal.Data.Unfold.Type (Unfold(..))
111-- import Streamly.String (encodeUtf8, decodeUtf8, foldLines)
112import Streamly.Internal.System.IO (defaultChunkSize)
114import qualified Streamly.Data.Array as A
115import qualified Streamly.Data.Unfold as UF
116import qualified Streamly.Internal.Data.Fold.Type as FL
117 (Step(..), snoc, reduce)
118import qualified Streamly.Internal.Data.Unfold as UF (bracketIO)
119import qualified Streamly.Internal.FileSystem.Handle as FH
120import qualified Streamly.Internal.Data.Stream.Chunked as AS
121import qualified Streamly.Data.Stream as S (fold, bracketIO, mapM)
123-------------------------------------------------------------------------------
124-- References
125-------------------------------------------------------------------------------
126--
127-- The following references may be useful to build an understanding about the
128-- file API design:
129--
130-- http://www.linux-mag.com/id/308/ for blocking/non-blocking IO on linux.
131-- https://lwn.net/Articles/612483/ Non-blocking buffered file read operations
132-- https://en.wikipedia.org/wiki/C_file_input/output for C APIs.
133-- https://docs.oracle.com/javase/tutorial/essential/io/file.html for Java API.
134-- https://www.w3.org/TR/FileAPI/ for http file API.
136-------------------------------------------------------------------------------
137-- Safe file reading
138-------------------------------------------------------------------------------
140-- | @'withFile' name mode act@ opens a file using 'openFile' and passes
141-- the resulting handle to the computation @act@. The handle will be
142-- closed on exit from 'withFile', whether by normal termination or by
143-- raising an exception. If closing the handle raises an exception, then
144-- this exception will be raised by 'withFile' rather than any exception
145-- raised by 'act'.
146--
147-- /Pre-release/
148--
149{-# INLINE withFile #-}
150withFile :: (MonadCatch m, MonadIO m)
151 => FilePath -> IOMode -> (Handle -> Stream m a) -> Stream m a
152withFile file mode = S.bracketIO (openFile file mode) hClose
154-- | Transform an 'Unfold' from a 'Handle' to an unfold from a 'FilePath'. The
155-- resulting unfold opens a handle in 'ReadMode', uses it using the supplied
156-- unfold and then makes sure that the handle is closed on normal termination
157-- or in case of an exception. If closing the handle raises an exception, then
158-- this exception will be raised by 'usingFile'.
159--
160-- /Pre-release/
161--
162{-# INLINE usingFile #-}
163usingFile :: (MonadCatch m, MonadIO m)
164 => Unfold m Handle a -> Unfold m FilePath a
165usingFile = UF.bracketIO (`openFile` ReadMode) hClose
167{-# INLINE usingFile2 #-}
168usingFile2 :: (MonadCatch m, MonadIO m)
169 => Unfold m (x, Handle) a -> Unfold m (x, FilePath) a
170usingFile2 = UF.bracketIO before after
172 where
174 before (x, file) = do
175 h <- openFile file ReadMode
176 return (x, h)
178 after (_, h) = hClose h
180{-# INLINE usingFile3 #-}
181usingFile3 :: (MonadCatch m, MonadIO m)
182 => Unfold m (x, y, z, Handle) a -> Unfold m (x, y, z, FilePath) a
183usingFile3 = UF.bracketIO before after
185 where
187 before (x, y, z, file) = do
188 h <- openFile file ReadMode
189 return (x, y, z, h)
191 after (_, _, _, h) = hClose h
193-------------------------------------------------------------------------------
194-- Array IO (Input)
195-------------------------------------------------------------------------------
197-- TODO readArrayOf
199-------------------------------------------------------------------------------
200-- Array IO (output)
201-------------------------------------------------------------------------------
203-- | Write an array to a file. Overwrites the file if it exists.
204--
205-- @since 0.7.0
206{-# INLINABLE putChunk #-}
207putChunk :: FilePath -> Array a -> IO ()
208putChunk file arr = SIO.withFile file WriteMode (`FH.putChunk` arr)
210-- | append an array to a file.
211--
212-- @since 0.7.0
213{-# INLINABLE appendArray #-}
214appendArray :: FilePath -> Array a -> IO ()
215appendArray file arr = SIO.withFile file AppendMode (`FH.putChunk` arr)
217-------------------------------------------------------------------------------
218-- Stream of Arrays IO
219-------------------------------------------------------------------------------
221-- | @readChunksWith size file@ reads a stream of arrays from file @file@.
222-- The maximum size of a single array is specified by @size@. The actual size
223-- read may be less than or equal to @size@.
224--
225-- @since 0.9.0
226{-# INLINE readChunksWith #-}
227readChunksWith :: (MonadCatch m, MonadIO m)
228 => Int -> FilePath -> Stream m (Array Word8)
229readChunksWith size file =
230 withFile file ReadMode (FH.readChunksWith size)
232{-# DEPRECATED toChunksWithBufferOf "Please use 'readChunksWith' instead" #-}
233{-# INLINE toChunksWithBufferOf #-}
234toChunksWithBufferOf :: (MonadCatch m, MonadIO m)
235 => Int -> FilePath -> Stream m (Array Word8)
236toChunksWithBufferOf = readChunksWith
238-- XXX read 'Array a' instead of Word8
239--
240-- | @readChunks file@ reads a stream of arrays from file @file@.
241-- The maximum size of a single array is limited to @defaultChunkSize@. The
242-- actual size read may be less than @defaultChunkSize@.
243--
244-- > readChunks = readChunksWith defaultChunkSize
245--
246-- @since 0.7.0
247{-# INLINE readChunks #-}
248readChunks :: (MonadCatch m, MonadIO m)
249 => FilePath -> Stream m (Array Word8)
250readChunks = readChunksWith defaultChunkSize
252{-# DEPRECATED toChunks "Please use 'readChunks' instead" #-}
253{-# INLINE toChunks #-}
254toChunks :: (MonadCatch m, MonadIO m) => FilePath -> Stream m (Array Word8)
255toChunks = readChunks
257-------------------------------------------------------------------------------
258-- Read File to Stream
259-------------------------------------------------------------------------------
261-- TODO for concurrent streams implement readahead IO. We can send multiple
262-- read requests at the same time. For serial case we can use async IO. We can
263-- also control the read throughput in mbps or IOPS.
265-- | Unfold the tuple @(bufsize, filepath)@ into a stream of 'Word8' arrays.
266-- Read requests to the IO device are performed using a buffer of size
267-- @bufsize@. The size of an array in the resulting stream is always less than
268-- or equal to @bufsize@.
269--
270-- /Pre-release/
271--
272{-# INLINE chunkReaderWith #-}
273chunkReaderWith :: (MonadCatch m, MonadIO m)
274 => Unfold m (Int, FilePath) (Array Word8)
275chunkReaderWith = usingFile2 FH.chunkReaderWith
277{-# DEPRECATED readChunksWithBufferOf
278 "Please use 'chunkReaderWith' instead" #-}
279{-# INLINE readChunksWithBufferOf #-}
280readChunksWithBufferOf :: (MonadCatch m, MonadIO m)
281 => Unfold m (Int, FilePath) (Array Word8)
282readChunksWithBufferOf = chunkReaderWith
284-- | Unfold the tuple @(from, to, bufsize, filepath)@ into a stream
285-- of 'Word8' arrays.
286-- Read requests to the IO device are performed using a buffer of size
287-- @bufsize@ starting from absolute offset of @from@ till the absolute
288-- position of @to@. The size of an array in the resulting stream is always
289-- less than or equal to @bufsize@.
290--
291-- /Pre-release/
292{-# INLINE chunkReaderFromToWith #-}
293chunkReaderFromToWith :: (MonadCatch m, MonadIO m) =>
294 Unfold m (Int, Int, Int, FilePath) (Array Word8)
295chunkReaderFromToWith = usingFile3 FH.chunkReaderFromToWith
297{-# DEPRECATED readChunksFromToWith
298 "Please use 'chunkReaderFromToWith' instead" #-}
299{-# INLINE readChunksFromToWith #-}
300readChunksFromToWith :: (MonadCatch m, MonadIO m) =>
301 Unfold m (Int, Int, Int, FilePath) (Array Word8)
302readChunksFromToWith = chunkReaderFromToWith
304-- | Unfolds a 'FilePath' into a stream of 'Word8' arrays. Requests to the IO
305-- device are performed using a buffer of size
306-- 'Streamly.Internal.Data.Array.Type.defaultChunkSize'. The
307-- size of arrays in the resulting stream are therefore less than or equal to
308-- 'Streamly.Internal.Data.Array.Type.defaultChunkSize'.
309--
310-- /Pre-release/
311{-# INLINE chunkReader #-}
312chunkReader :: (MonadCatch m, MonadIO m) => Unfold m FilePath (Array Word8)
313chunkReader = usingFile FH.chunkReader
315-- | Unfolds the tuple @(bufsize, filepath)@ into a byte stream, read requests
316-- to the IO device are performed using buffers of @bufsize@.
317--
318-- /Pre-release/
319{-# INLINE readerWith #-}
320readerWith :: (MonadCatch m, MonadIO m) => Unfold m (Int, FilePath) Word8
321readerWith = usingFile2 FH.readerWith
323{-# DEPRECATED readWithBufferOf "Please use 'readerWith' instead" #-}
324{-# INLINE readWithBufferOf #-}
325readWithBufferOf :: (MonadCatch m, MonadIO m) =>
326 Unfold m (Int, FilePath) Word8
327readWithBufferOf = readerWith
329-- | Unfolds a file path into a byte stream. IO requests to the device are
330-- performed in sizes of
331-- 'Streamly.Internal.Data.Array.Type.defaultChunkSize'.
332--
333-- /Pre-release/
334{-# INLINE reader #-}
335reader :: (MonadCatch m, MonadIO m) => Unfold m FilePath Word8
336reader = UF.many A.reader (usingFile FH.chunkReader)
338-- | Generate a stream of bytes from a file specified by path. The stream ends
339-- when EOF is encountered. File is locked using multiple reader and single
340-- writer locking mode.
341--
342-- /Pre-release/
343--
344{-# INLINE read #-}
345read :: (MonadCatch m, MonadIO m) => FilePath -> Stream m Word8
346read file = AS.concat $ withFile file ReadMode FH.readChunks
348{-# DEPRECATED toBytes "Please use 'read' instead" #-}
349{-# INLINE toBytes #-}
350toBytes :: (MonadCatch m, MonadIO m) => FilePath -> Stream m Word8
351toBytes = read
353{-
354-- | Generate a stream of elements of the given type from a file 'Handle'. The
355-- stream ends when EOF is encountered. File is not locked for exclusive reads,
356-- writers can keep writing to the file.
357--
358-- @since 0.7.0
359{-# INLINE readShared #-}
360readShared :: MonadIO m => Handle -> Stream m Word8
361readShared = undefined
362-}
364-------------------------------------------------------------------------------
365-- Writing
366-------------------------------------------------------------------------------
368{-# INLINE fromChunksMode #-}
369fromChunksMode :: (MonadIO m, MonadCatch m)
370 => IOMode -> FilePath -> Stream m (Array a) -> m ()
371fromChunksMode mode file xs = S.fold drain $
372 withFile file mode (\h -> S.mapM (FH.putChunk h) xs)
374-- | Write a stream of arrays to a file. Overwrites the file if it exists.
375--
376-- @since 0.7.0
377{-# INLINE fromChunks #-}
378fromChunks :: (MonadIO m, MonadCatch m)
379 => FilePath -> Stream m (Array a) -> m ()
380fromChunks = fromChunksMode WriteMode
382-- GHC buffer size dEFAULT_FD_BUFFER_SIZE=8192 bytes.
383--
384-- XXX test this
385-- Note that if you use a chunk size less than 8K (GHC's default buffer
386-- size) then you are advised to use 'NOBuffering' mode on the 'Handle' in case you
387-- do not want buffering to occur at GHC level as well. Same thing applies to
388-- writes as well.
390-- | Like 'write' but provides control over the write buffer. Output will
391-- be written to the IO device as soon as we collect the specified number of
392-- input elements.
393--
394-- @since 0.9.0
395{-# INLINE fromBytesWith #-}
396fromBytesWith :: (MonadIO m, MonadCatch m)
397 => Int -> FilePath -> Stream m Word8 -> m ()
398fromBytesWith n file xs = fromChunks file $ AS.arraysOf n xs
400{-# DEPRECATED fromBytesWithBufferOf "Please use 'fromBytesWith' instead" #-}
401{-# INLINE fromBytesWithBufferOf #-}
402fromBytesWithBufferOf :: (MonadIO m, MonadCatch m)
403 => Int -> FilePath -> Stream m Word8 -> m ()
404fromBytesWithBufferOf = fromBytesWith
406-- > write = 'writeWith' defaultChunkSize
407--
408-- | Write a byte stream to a file. Combines the bytes in chunks of size
409-- up to 'A.defaultChunkSize' before writing. If the file exists it is
410-- truncated to zero size before writing. If the file does not exist it is
411-- created. File is locked using single writer locking mode.
412--
413-- /Pre-release/
414{-# INLINE fromBytes #-}
415fromBytes :: (MonadIO m, MonadCatch m) => FilePath -> Stream m Word8 -> m ()
416fromBytes = fromBytesWith defaultChunkSize
418{-
419{-# INLINE write #-}
420write :: (MonadIO m, Storable a) => Handle -> Stream m a -> m ()
421write = toHandleWith A.defaultChunkSize
422-}
424-- | Write a stream of chunks to a handle. Each chunk in the stream is written
425-- to the device as a separate IO request.
426--
427-- /Pre-release/
428{-# INLINE writeChunks #-}
429writeChunks :: (MonadIO m, MonadCatch m)
430 => FilePath -> Fold m (Array a) ()
431writeChunks path = Fold step initial extract
432 where
433 initial = do
434 h <- liftIO (openFile path WriteMode)
435 fld <- FL.reduce (FH.writeChunks h)
436 `MC.onException` liftIO (hClose h)
437 return $ FL.Partial (fld, h)
438 step (fld, h) x = do
439 r <- FL.snoc fld x `MC.onException` liftIO (hClose h)
440 return $ FL.Partial (r, h)
441 extract (Fold _ initial1 extract1, h) = do
442 liftIO $ hClose h
443 res <- initial1
444 case res of
445 FL.Partial fs -> extract1 fs
446 FL.Done fb -> return fb
448-- | @writeWith chunkSize handle@ writes the input stream to @handle@.
449-- Bytes in the input stream are collected into a buffer until we have a chunk
450-- of size @chunkSize@ and then written to the IO device.
451--
452-- /Pre-release/
453{-# INLINE writeWith #-}
454writeWith :: (MonadIO m, MonadCatch m)
455 => Int -> FilePath -> Fold m Word8 ()
456writeWith n path =
457 chunksOf n (writeNUnsafe n) (writeChunks path)
459{-# DEPRECATED writeWithBufferOf "Please use 'writeWith' instead" #-}
460{-# INLINE writeWithBufferOf #-}
461writeWithBufferOf :: (MonadIO m, MonadCatch m)
462 => Int -> FilePath -> Fold m Word8 ()
463writeWithBufferOf = writeWith
465-- > write = 'writeWith' A.defaultChunkSize
466--
467-- | Write a byte stream to a file. Accumulates the input in chunks of up to
468-- 'Streamly.Internal.Data.Array.Type.defaultChunkSize' before writing to
469-- the IO device.
470--
471-- /Pre-release/
472--
473{-# INLINE write #-}
474write :: (MonadIO m, MonadCatch m) => FilePath -> Fold m Word8 ()
475write = writeWith defaultChunkSize
477-- | Append a stream of arrays to a file.
478--
479-- @since 0.7.0
480{-# INLINE appendChunks #-}
481appendChunks :: (MonadIO m, MonadCatch m)
482 => FilePath -> Stream m (Array a) -> m ()
483appendChunks = fromChunksMode AppendMode
485-- | Like 'append' but provides control over the write buffer. Output will
486-- be written to the IO device as soon as we collect the specified number of
487-- input elements.
488--
489-- @since 0.9.0
490{-# INLINE appendWith #-}
491appendWith :: (MonadIO m, MonadCatch m)
492 => Int -> FilePath -> Stream m Word8 -> m ()
493appendWith n file xs = appendChunks file $ AS.arraysOf n xs
495-- | Append a byte stream to a file. Combines the bytes in chunks of size up to
496-- 'A.defaultChunkSize' before writing. If the file exists then the new data
497-- is appended to the file. If the file does not exist it is created. File is
498-- locked using single writer locking mode.
499--
500-- @since 0.7.0
501{-# INLINE append #-}
502append :: (MonadIO m, MonadCatch m) => FilePath -> Stream m Word8 -> m ()
503append = appendWith defaultChunkSize
505{-
506-- | Like 'append' but the file is not locked for exclusive writes.
507--
508-- @since 0.7.0
509{-# INLINE appendShared #-}
510appendShared :: MonadIO m => Handle -> Stream m Word8 -> m ()
511appendShared = undefined
512-}
514-------------------------------------------------------------------------------
515-- IO with encoding/decoding Unicode characters
516-------------------------------------------------------------------------------
518{-
519-- |
520-- > readUtf8 = decodeUtf8 . read
521--
522-- Read a UTF8 encoded stream of unicode characters from a file handle.
523--
524-- @since 0.7.0
525{-# INLINE readUtf8 #-}
526readUtf8 :: MonadIO m => Handle -> Stream m Char
527readUtf8 = decodeUtf8 . read
529-- |
530-- > writeUtf8 h s = write h $ encodeUtf8 s
531--
532-- Encode a stream of unicode characters to UTF8 and write it to the given file
533-- handle. Default block buffering applies to the writes.
534--
535-- @since 0.7.0
536{-# INLINE writeUtf8 #-}
537writeUtf8 :: MonadIO m => Handle -> Stream m Char -> m ()
538writeUtf8 h s = write h $ encodeUtf8 s
540-- | Write a stream of unicode characters after encoding to UTF-8 in chunks
541-- separated by a linefeed character @'\n'@. If the size of the buffer exceeds
542-- @defaultChunkSize@ and a linefeed is not yet found, the buffer is written
543-- anyway. This is similar to writing to a 'Handle' with the 'LineBuffering'
544-- option.
545--
546-- @since 0.7.0
547{-# INLINE writeUtf8ByLines #-}
548writeUtf8ByLines :: MonadIO m => Handle -> Stream m Char -> m ()
549writeUtf8ByLines = undefined
551-- | Read UTF-8 lines from a file handle and apply the specified fold to each
552-- line. This is similar to reading a 'Handle' with the 'LineBuffering' option.
553--
554-- @since 0.7.0
555{-# INLINE readLines #-}
556readLines :: MonadIO m => Handle -> Fold m Char b -> Stream m b
557readLines h f = foldLines (readUtf8 h) f
559-------------------------------------------------------------------------------
560-- Framing on a sequence
561-------------------------------------------------------------------------------
563-- | Read a stream from a file handle and split it into frames delimited by
564-- the specified sequence of elements. The supplied fold is applied on each
565-- frame.
566--
567-- @since 0.7.0
568{-# INLINE readFrames #-}
569readFrames :: (MonadIO m, Storable a)
570 => Array a -> Handle -> Fold m a b -> Stream m b
571readFrames = undefined -- foldFrames . read
573-- | Write a stream to the given file handle buffering up to frames separated
574-- by the given sequence or up to a maximum of @defaultChunkSize@.
575--
576-- @since 0.7.0
577{-# INLINE writeByFrames #-}
578writeByFrames :: (MonadIO m, Storable a)
579 => Array a -> Handle -> Stream m a -> m ()
580writeByFrames = undefined
582-------------------------------------------------------------------------------
583-- Random Access IO (Seek)
584-------------------------------------------------------------------------------
586-- XXX handles could be shared, so we may not want to use the handle state at
587-- all for these APIs. we can use pread and pwrite instead. On windows we will
588-- need to use readFile/writeFile with an offset argument.
590-------------------------------------------------------------------------------
592-- | Read the element at the given index treating the file as an array.
593--
594-- @since 0.7.0
595{-# INLINE readIndex #-}
596readIndex :: Storable a => Handle -> Int -> Maybe a
597readIndex arr i = undefined
599-- NOTE: To represent a range to read we have chosen (start, size) instead of
600-- (start, end). This helps in removing the ambiguity of whether "end" is
601-- included in the range or not.
602--
603-- We could avoid specifying the range to be read and instead use "take size"
604-- on the stream, but it may end up reading more and then consume it partially.
606-- | @readSliceWith chunkSize handle pos len@ reads up to @len@ bytes
607-- from @handle@ starting at the offset @pos@ from the beginning of the file.
608--
609-- Reads are performed in chunks of size @chunkSize@. For block devices, to
610-- avoid reading partial blocks @chunkSize@ must align with the block size of
611-- the underlying device. If the underlying block size is unknown, it is a good
612-- idea to keep it a multiple 4KiB. This API ensures that the start of each
613-- chunk is aligned with @chunkSize@ from second chunk onwards.
614--
615{-# INLINE readSliceWith #-}
616readSliceWith :: (MonadIO m, Storable a)
617 => Int -> Handle -> Int -> Int -> Stream m a
618readSliceWith chunkSize h pos len = undefined
620-- | @readSlice h i count@ streams a slice from the file handle @h@ starting
621-- at index @i@ and reading up to @count@ elements in the forward direction
622-- ending at the index @i + count - 1@.
623--
624-- @since 0.7.0
625{-# INLINE readSlice #-}
626readSlice :: (MonadIO m, Storable a)
627 => Handle -> Int -> Int -> Stream m a
628readSlice = readSliceWith defaultChunkSize
630-- | @readSliceRev h i count@ streams a slice from the file handle @h@ starting
631-- at index @i@ and reading up to @count@ elements in the reverse direction
632-- ending at the index @i - count + 1@.
633--
634-- @since 0.7.0
635{-# INLINE readSliceRev #-}
636readSliceRev :: (MonadIO m, Storable a)
637 => Handle -> Int -> Int -> Stream m a
638readSliceRev h i count = undefined
640-- | Write the given element at the given index in the file.
641--
642-- @since 0.7.0
643{-# INLINE writeIndex #-}
644writeIndex :: (MonadIO m, Storable a) => Handle -> Int -> a -> m ()
645writeIndex h i a = undefined
647-- | @writeSlice h i count stream@ writes a stream to the file handle @h@
648-- starting at index @i@ and writing up to @count@ elements in the forward
649-- direction ending at the index @i + count - 1@.
650--
651-- @since 0.7.0
652{-# INLINE writeSlice #-}
653writeSlice :: (Monad m, Storable a)
654 => Handle -> Int -> Int -> Stream m a -> m ()
655writeSlice h i len s = undefined
657-- | @writeSliceRev h i count stream@ writes a stream to the file handle @h@
658-- starting at index @i@ and writing up to @count@ elements in the reverse
659-- direction ending at the index @i - count + 1@.
660--
661-- @since 0.7.0
662{-# INLINE writeSliceRev #-}
663writeSliceRev :: (Monad m, Storable a)
664 => Handle -> Int -> Int -> Stream m a -> m ()
665writeSliceRev arr i len s = undefined
666-}