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