on be953ba help sign in
667 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.Control.Concurrent (MonadAsync)
108import Streamly.Internal.Data.Array.Unboxed.Type (Array(..), writeNUnsafe)
109import Streamly.Internal.Data.Fold.Type (Fold(..))
110import Streamly.Data.Stream (Stream)
111import Streamly.Internal.Data.Unfold.Type (Unfold(..))
112-- import Streamly.String (encodeUtf8, decodeUtf8, foldLines)
113import Streamly.Internal.System.IO (defaultChunkSize)
115import qualified Streamly.Data.Array.Unboxed as A
116import qualified Streamly.Data.Unfold as UF
117import qualified Streamly.Internal.Data.Fold.Type as FL
118 (Step(..), snoc, initialize)
119import qualified Streamly.Internal.Data.Unfold as UF (bracketIO)
120import qualified Streamly.Internal.FileSystem.Handle as FH
121import qualified Streamly.Internal.Data.Array.Unboxed.Stream as AS
122import qualified Streamly.Data.Stream as S (fold, bracketIO, mapM)
124-------------------------------------------------------------------------------
125-- References
126-------------------------------------------------------------------------------
127--
128-- The following references may be useful to build an understanding about the
129-- file API design:
130--
131-- http://www.linux-mag.com/id/308/ for blocking/non-blocking IO on linux.
132-- https://lwn.net/Articles/612483/ Non-blocking buffered file read operations
133-- https://en.wikipedia.org/wiki/C_file_input/output for C APIs.
134-- https://docs.oracle.com/javase/tutorial/essential/io/file.html for Java API.
135-- https://www.w3.org/TR/FileAPI/ for http file API.
137-------------------------------------------------------------------------------
138-- Safe file reading
139-------------------------------------------------------------------------------
141-- | @'withFile' name mode act@ opens a file using 'openFile' and passes
142-- the resulting handle to the computation @act@. The handle will be
143-- closed on exit from 'withFile', whether by normal termination or by
144-- raising an exception. If closing the handle raises an exception, then
145-- this exception will be raised by 'withFile' rather than any exception
146-- raised by 'act'.
147--
148-- /Pre-release/
149--
150{-# INLINE withFile #-}
151withFile :: (MonadCatch m, MonadAsync m)
152 => FilePath -> IOMode -> (Handle -> Stream m a) -> Stream m a
153withFile file mode = S.bracketIO (openFile file mode) hClose
155-- | Transform an 'Unfold' from a 'Handle' to an unfold from a 'FilePath'. The
156-- resulting unfold opens a handle in 'ReadMode', uses it using the supplied
157-- unfold and then makes sure that the handle is closed on normal termination
158-- or in case of an exception. If closing the handle raises an exception, then
159-- this exception will be raised by 'usingFile'.
160--
161-- /Pre-release/
162--
163{-# INLINE usingFile #-}
164usingFile :: (MonadCatch m, MonadAsync m)
165 => Unfold m Handle a -> Unfold m FilePath a
166usingFile = UF.bracketIO (`openFile` ReadMode) hClose
168{-# INLINE usingFile2 #-}
169usingFile2 :: (MonadCatch m, MonadAsync m)
170 => Unfold m (x, Handle) a -> Unfold m (x, FilePath) a
171usingFile2 = UF.bracketIO before after
173 where
175 before (x, file) = do
176 h <- openFile file ReadMode
177 return (x, h)
179 after (_, h) = hClose h
181{-# INLINE usingFile3 #-}
182usingFile3 :: (MonadCatch m, MonadAsync m)
183 => Unfold m (x, y, z, Handle) a -> Unfold m (x, y, z, FilePath) a
184usingFile3 = UF.bracketIO before after
186 where
188 before (x, y, z, file) = do
189 h <- openFile file ReadMode
190 return (x, y, z, h)
192 after (_, _, _, h) = hClose h
194-------------------------------------------------------------------------------
195-- Array IO (Input)
196-------------------------------------------------------------------------------
198-- TODO readArrayOf
200-------------------------------------------------------------------------------
201-- Array IO (output)
202-------------------------------------------------------------------------------
204-- | Write an array to a file. Overwrites the file if it exists.
205--
206-- @since 0.7.0
207{-# INLINABLE putChunk #-}
208putChunk :: FilePath -> Array a -> IO ()
209putChunk file arr = SIO.withFile file WriteMode (`FH.putChunk` arr)
211-- | append an array to a file.
212--
213-- @since 0.7.0
214{-# INLINABLE appendArray #-}
215appendArray :: FilePath -> Array a -> IO ()
216appendArray 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-- @since 0.9.0
227{-# INLINE readChunksWith #-}
228readChunksWith :: (MonadCatch m, MonadAsync m)
229 => Int -> FilePath -> Stream m (Array Word8)
230readChunksWith size file =
231 withFile file ReadMode (FH.readChunksWith size)
233{-# DEPRECATED toChunksWithBufferOf "Please use 'readChunksWith' instead" #-}
234{-# INLINE toChunksWithBufferOf #-}
235toChunksWithBufferOf :: (MonadCatch m, MonadAsync m)
236 => Int -> FilePath -> Stream m (Array Word8)
237toChunksWithBufferOf = readChunksWith
239-- XXX read 'Array a' instead of Word8
240--
241-- | @readChunks file@ reads a stream of arrays from file @file@.
242-- The maximum size of a single array is limited to @defaultChunkSize@. The
243-- actual size read may be less than @defaultChunkSize@.
244--
245-- > readChunks = readChunksWith defaultChunkSize
246--
247-- @since 0.7.0
248{-# INLINE readChunks #-}
249readChunks :: (MonadCatch m, MonadAsync m)
250 => FilePath -> Stream m (Array Word8)
251readChunks = readChunksWith defaultChunkSize
253{-# DEPRECATED toChunks "Please use 'readChunks' instead" #-}
254{-# INLINE toChunks #-}
255toChunks :: (MonadCatch m, MonadAsync m) => FilePath -> Stream m (Array Word8)
256toChunks = readChunks
258-------------------------------------------------------------------------------
259-- Read File to Stream
260-------------------------------------------------------------------------------
262-- TODO for concurrent streams implement readahead IO. We can send multiple
263-- read requests at the same time. For serial case we can use async IO. We can
264-- also control the read throughput in mbps or IOPS.
266-- | Unfold the tuple @(bufsize, filepath)@ into a stream of 'Word8' arrays.
267-- Read requests to the IO device are performed using a buffer of size
268-- @bufsize@. The size of an array in the resulting stream is always less than
269-- or equal to @bufsize@.
270--
271-- /Pre-release/
272--
273{-# INLINE chunkReaderWith #-}
274chunkReaderWith :: (MonadCatch m, MonadAsync m)
275 => Unfold m (Int, FilePath) (Array Word8)
276chunkReaderWith = usingFile2 FH.chunkReaderWith
278{-# DEPRECATED readChunksWithBufferOf
279 "Please use 'chunkReaderWith' instead" #-}
280{-# INLINE readChunksWithBufferOf #-}
281readChunksWithBufferOf :: (MonadCatch m, MonadAsync m)
282 => Unfold m (Int, FilePath) (Array Word8)
283readChunksWithBufferOf = chunkReaderWith
285-- | Unfold the tuple @(from, to, bufsize, filepath)@ into a stream
286-- of 'Word8' arrays.
287-- Read requests to the IO device are performed using a buffer of size
288-- @bufsize@ starting from absolute offset of @from@ till the absolute
289-- position of @to@. The size of an array in the resulting stream is always
290-- less than or equal to @bufsize@.
291--
292-- /Pre-release/
293{-# INLINE chunkReaderFromToWith #-}
294chunkReaderFromToWith :: (MonadCatch m, MonadAsync m) =>
295 Unfold m (Int, Int, Int, FilePath) (Array Word8)
296chunkReaderFromToWith = usingFile3 FH.chunkReaderFromToWith
298{-# DEPRECATED readChunksFromToWith
299 "Please use 'chunkReaderFromToWith' instead" #-}
300{-# INLINE readChunksFromToWith #-}
301readChunksFromToWith :: (MonadCatch m, MonadAsync m) =>
302 Unfold m (Int, Int, Int, FilePath) (Array Word8)
303readChunksFromToWith = chunkReaderFromToWith
305-- | Unfolds a 'FilePath' into a stream of 'Word8' arrays. Requests to the IO
306-- device are performed using a buffer of size
307-- 'Streamly.Internal.Data.Array.Unboxed.Type.defaultChunkSize'. The
308-- size of arrays in the resulting stream are therefore less than or equal to
309-- 'Streamly.Internal.Data.Array.Unboxed.Type.defaultChunkSize'.
310--
311-- /Pre-release/
312{-# INLINE chunkReader #-}
313chunkReader :: (MonadCatch m, MonadAsync m) => Unfold m FilePath (Array Word8)
314chunkReader = usingFile FH.chunkReader
316-- | Unfolds the tuple @(bufsize, filepath)@ into a byte stream, read requests
317-- to the IO device are performed using buffers of @bufsize@.
318--
319-- /Pre-release/
320{-# INLINE readerWith #-}
321readerWith :: (MonadCatch m, MonadAsync m) => Unfold m (Int, FilePath) Word8
322readerWith = usingFile2 FH.readerWith
324{-# DEPRECATED readWithBufferOf "Please use 'readerWith' instead" #-}
325{-# INLINE readWithBufferOf #-}
326readWithBufferOf :: (MonadCatch m, MonadAsync m) =>
327 Unfold m (Int, FilePath) Word8
328readWithBufferOf = readerWith
330-- | Unfolds a file path into a byte stream. IO requests to the device are
331-- performed in sizes of
332-- 'Streamly.Internal.Data.Array.Unboxed.Type.defaultChunkSize'.
333--
334-- /Pre-release/
335{-# INLINE reader #-}
336reader :: (MonadCatch m, MonadAsync m) => Unfold m FilePath Word8
337reader = UF.many A.reader (usingFile FH.chunkReader)
339-- | Generate a stream of bytes from a file specified by path. The stream ends
340-- when EOF is encountered. File is locked using multiple reader and single
341-- writer locking mode.
342--
343-- /Pre-release/
344--
345{-# INLINE read #-}
346read :: (MonadCatch m, MonadAsync m) => FilePath -> Stream m Word8
347read file = AS.concat $ withFile file ReadMode FH.readChunks
349{-# DEPRECATED toBytes "Please use 'read' instead" #-}
350{-# INLINE toBytes #-}
351toBytes :: (MonadCatch m, MonadAsync m) => FilePath -> Stream m Word8
352toBytes = read
354{-
355-- | Generate a stream of elements of the given type from a file 'Handle'. The
356-- stream ends when EOF is encountered. File is not locked for exclusive reads,
357-- writers can keep writing to the file.
358--
359-- @since 0.7.0
360{-# INLINE readShared #-}
361readShared :: MonadIO m => Handle -> Stream m Word8
362readShared = undefined
363-}
365-------------------------------------------------------------------------------
366-- Writing
367-------------------------------------------------------------------------------
369{-# INLINE fromChunksMode #-}
370fromChunksMode :: (MonadAsync m, MonadCatch m)
371 => IOMode -> FilePath -> Stream m (Array a) -> m ()
372fromChunksMode mode file xs = S.fold drain $
373 withFile file mode (\h -> S.mapM (FH.putChunk h) xs)
375-- | Write a stream of arrays to a file. Overwrites the file if it exists.
376--
377-- @since 0.7.0
378{-# INLINE fromChunks #-}
379fromChunks :: (MonadAsync m, MonadCatch m)
380 => FilePath -> Stream m (Array a) -> m ()
381fromChunks = fromChunksMode WriteMode
383-- GHC buffer size dEFAULT_FD_BUFFER_SIZE=8192 bytes.
384--
385-- XXX test this
386-- Note that if you use a chunk size less than 8K (GHC's default buffer
387-- size) then you are advised to use 'NOBuffering' mode on the 'Handle' in case you
388-- do not want buffering to occur at GHC level as well. Same thing applies to
389-- writes as well.
391-- | Like 'write' but provides control over the write buffer. Output will
392-- be written to the IO device as soon as we collect the specified number of
393-- input elements.
394--
395-- @since 0.9.0
396{-# INLINE fromBytesWith #-}
397fromBytesWith :: (MonadAsync m, MonadCatch m)
398 => Int -> FilePath -> Stream m Word8 -> m ()
399fromBytesWith n file xs = fromChunks file $ AS.arraysOf n xs
401{-# DEPRECATED fromBytesWithBufferOf "Please use 'fromBytesWith' instead" #-}
402{-# INLINE fromBytesWithBufferOf #-}
403fromBytesWithBufferOf :: (MonadAsync m, MonadCatch m)
404 => Int -> FilePath -> Stream m Word8 -> m ()
405fromBytesWithBufferOf = fromBytesWith
407-- > write = 'writeWith' defaultChunkSize
408--
409-- | Write a byte stream to a file. Combines the bytes in chunks of size
410-- up to 'A.defaultChunkSize' before writing. If the file exists it is
411-- truncated to zero size before writing. If the file does not exist it is
412-- created. File is locked using single writer locking mode.
413--
414-- /Pre-release/
415{-# INLINE fromBytes #-}
416fromBytes :: (MonadAsync m, MonadCatch m) => FilePath -> Stream m Word8 -> m ()
417fromBytes = fromBytesWith defaultChunkSize
419{-
420{-# INLINE write #-}
421write :: (MonadIO m, Storable a) => Handle -> Stream m a -> m ()
422write = toHandleWith A.defaultChunkSize
423-}
425-- | Write a stream of chunks to a handle. Each chunk in the stream is written
426-- to the device as a separate IO request.
427--
428-- /Pre-release/
429{-# INLINE writeChunks #-}
430writeChunks :: (MonadIO m, MonadCatch m)
431 => FilePath -> Fold m (Array a) ()
432writeChunks path = Fold step initial extract
433 where
434 initial = do
435 h <- liftIO (openFile path WriteMode)
436 fld <- FL.initialize (FH.writeChunks h)
437 `MC.onException` liftIO (hClose h)
438 return $ FL.Partial (fld, h)
439 step (fld, h) x = do
440 r <- FL.snoc fld x `MC.onException` liftIO (hClose h)
441 return $ FL.Partial (r, h)
442 extract (Fold _ initial1 extract1, h) = do
443 liftIO $ hClose h
444 res <- initial1
445 case res of
446 FL.Partial fs -> extract1 fs
447 FL.Done fb -> return fb
449-- | @writeWith chunkSize handle@ writes the input stream to @handle@.
450-- Bytes in the input stream are collected into a buffer until we have a chunk
451-- of size @chunkSize@ and then written to the IO device.
452--
453-- /Pre-release/
454{-# INLINE writeWith #-}
455writeWith :: (MonadIO m, MonadCatch m)
456 => Int -> FilePath -> Fold m Word8 ()
457writeWith n path =
458 chunksOf n (writeNUnsafe n) (writeChunks path)
460{-# DEPRECATED writeWithBufferOf "Please use 'writeWith' instead" #-}
461{-# INLINE writeWithBufferOf #-}
462writeWithBufferOf :: (MonadIO m, MonadCatch m)
463 => Int -> FilePath -> Fold m Word8 ()
464writeWithBufferOf = writeWith
466-- > write = 'writeWith' A.defaultChunkSize
467--
468-- | Write a byte stream to a file. Accumulates the input in chunks of up to
469-- 'Streamly.Internal.Data.Array.Unboxed.Type.defaultChunkSize' before writing to
470-- the IO device.
471--
472-- /Pre-release/
473--
474{-# INLINE write #-}
475write :: (MonadIO m, MonadCatch m) => FilePath -> Fold m Word8 ()
476write = writeWith defaultChunkSize
478-- | Append a stream of arrays to a file.
479--
480-- @since 0.7.0
481{-# INLINE appendChunks #-}
482appendChunks :: (MonadAsync m, MonadCatch m)
483 => FilePath -> Stream m (Array a) -> m ()
484appendChunks = fromChunksMode AppendMode
486-- | Like 'append' but provides control over the write buffer. Output will
487-- be written to the IO device as soon as we collect the specified number of
488-- input elements.
489--
490-- @since 0.9.0
491{-# INLINE appendWith #-}
492appendWith :: (MonadAsync m, MonadCatch m)
493 => Int -> FilePath -> Stream m Word8 -> m ()
494appendWith n file xs = appendChunks file $ AS.arraysOf n xs
496-- | Append a byte stream to a file. Combines the bytes in chunks of size up to
497-- 'A.defaultChunkSize' before writing. If the file exists then the new data
498-- is appended to the file. If the file does not exist it is created. File is
499-- locked using single writer locking mode.
500--
501-- @since 0.7.0
502{-# INLINE append #-}
503append :: (MonadAsync m, MonadCatch m) => FilePath -> Stream m Word8 -> m ()
504append = appendWith defaultChunkSize
506{-
507-- | Like 'append' but the file is not locked for exclusive writes.
508--
509-- @since 0.7.0
510{-# INLINE appendShared #-}
511appendShared :: MonadIO m => Handle -> Stream m Word8 -> m ()
512appendShared = undefined
513-}
515-------------------------------------------------------------------------------
516-- IO with encoding/decoding Unicode characters
517-------------------------------------------------------------------------------
519{-
520-- |
521-- > readUtf8 = decodeUtf8 . read
522--
523-- Read a UTF8 encoded stream of unicode characters from a file handle.
524--
525-- @since 0.7.0
526{-# INLINE readUtf8 #-}
527readUtf8 :: MonadIO m => Handle -> Stream m Char
528readUtf8 = decodeUtf8 . read
530-- |
531-- > writeUtf8 h s = write h $ encodeUtf8 s
532--
533-- Encode a stream of unicode characters to UTF8 and write it to the given file
534-- handle. Default block buffering applies to the writes.
535--
536-- @since 0.7.0
537{-# INLINE writeUtf8 #-}
538writeUtf8 :: MonadIO m => Handle -> Stream m Char -> m ()
539writeUtf8 h s = write h $ encodeUtf8 s
541-- | Write a stream of unicode characters after encoding to UTF-8 in chunks
542-- separated by a linefeed character @'\n'@. If the size of the buffer exceeds
543-- @defaultChunkSize@ and a linefeed is not yet found, the buffer is written
544-- anyway. This is similar to writing to a 'Handle' with the 'LineBuffering'
545-- option.
546--
547-- @since 0.7.0
548{-# INLINE writeUtf8ByLines #-}
549writeUtf8ByLines :: MonadIO m => Handle -> Stream m Char -> m ()
550writeUtf8ByLines = undefined
552-- | Read UTF-8 lines from a file handle and apply the specified fold to each
553-- line. This is similar to reading a 'Handle' with the 'LineBuffering' option.
554--
555-- @since 0.7.0
556{-# INLINE readLines #-}
557readLines :: MonadIO m => Handle -> Fold m Char b -> Stream m b
558readLines h f = foldLines (readUtf8 h) f
560-------------------------------------------------------------------------------
561-- Framing on a sequence
562-------------------------------------------------------------------------------
564-- | Read a stream from a file handle and split it into frames delimited by
565-- the specified sequence of elements. The supplied fold is applied on each
566-- frame.
567--
568-- @since 0.7.0
569{-# INLINE readFrames #-}
570readFrames :: (MonadIO m, Storable a)
571 => Array a -> Handle -> Fold m a b -> Stream m b
572readFrames = undefined -- foldFrames . read
574-- | Write a stream to the given file handle buffering up to frames separated
575-- by the given sequence or up to a maximum of @defaultChunkSize@.
576--
577-- @since 0.7.0
578{-# INLINE writeByFrames #-}
579writeByFrames :: (MonadIO m, Storable a)
580 => Array a -> Handle -> Stream m a -> m ()
581writeByFrames = undefined
583-------------------------------------------------------------------------------
584-- Random Access IO (Seek)
585-------------------------------------------------------------------------------
587-- XXX handles could be shared, so we may not want to use the handle state at
588-- all for these APIs. we can use pread and pwrite instead. On windows we will
589-- need to use readFile/writeFile with an offset argument.
591-------------------------------------------------------------------------------
593-- | Read the element at the given index treating the file as an array.
594--
595-- @since 0.7.0
596{-# INLINE readIndex #-}
597readIndex :: Storable a => Handle -> Int -> Maybe a
598readIndex arr i = undefined
600-- NOTE: To represent a range to read we have chosen (start, size) instead of
601-- (start, end). This helps in removing the ambiguity of whether "end" is
602-- included in the range or not.
603--
604-- We could avoid specifying the range to be read and instead use "take size"
605-- on the stream, but it may end up reading more and then consume it partially.
607-- | @readSliceWith chunkSize handle pos len@ reads up to @len@ bytes
608-- from @handle@ starting at the offset @pos@ from the beginning of the file.
609--
610-- Reads are performed in chunks of size @chunkSize@. For block devices, to
611-- avoid reading partial blocks @chunkSize@ must align with the block size of
612-- the underlying device. If the underlying block size is unknown, it is a good
613-- idea to keep it a multiple 4KiB. This API ensures that the start of each
614-- chunk is aligned with @chunkSize@ from second chunk onwards.
615--
616{-# INLINE readSliceWith #-}
617readSliceWith :: (MonadIO m, Storable a)
618 => Int -> Handle -> Int -> Int -> Stream m a
619readSliceWith chunkSize h pos len = undefined
621-- | @readSlice h i count@ streams a slice from the file handle @h@ starting
622-- at index @i@ and reading up to @count@ elements in the forward direction
623-- ending at the index @i + count - 1@.
624--
625-- @since 0.7.0
626{-# INLINE readSlice #-}
627readSlice :: (MonadIO m, Storable a)
628 => Handle -> Int -> Int -> Stream m a
629readSlice = readSliceWith defaultChunkSize
631-- | @readSliceRev h i count@ streams a slice from the file handle @h@ starting
632-- at index @i@ and reading up to @count@ elements in the reverse direction
633-- ending at the index @i - count + 1@.
634--
635-- @since 0.7.0
636{-# INLINE readSliceRev #-}
637readSliceRev :: (MonadIO m, Storable a)
638 => Handle -> Int -> Int -> Stream m a
639readSliceRev h i count = undefined
641-- | Write the given element at the given index in the file.
642--
643-- @since 0.7.0
644{-# INLINE writeIndex #-}
645writeIndex :: (MonadIO m, Storable a) => Handle -> Int -> a -> m ()
646writeIndex h i a = undefined
648-- | @writeSlice h i count stream@ writes a stream to the file handle @h@
649-- starting at index @i@ and writing up to @count@ elements in the forward
650-- direction ending at the index @i + count - 1@.
651--
652-- @since 0.7.0
653{-# INLINE writeSlice #-}
654writeSlice :: (Monad m, Storable a)
655 => Handle -> Int -> Int -> Stream m a -> m ()
656writeSlice h i len s = undefined
658-- | @writeSliceRev h i count stream@ writes a stream to the file handle @h@
659-- starting at index @i@ and writing up to @count@ elements in the reverse
660-- direction ending at the index @i - count + 1@.
661--
662-- @since 0.7.0
663{-# INLINE writeSliceRev #-}
664writeSliceRev :: (Monad m, Storable a)
665 => Handle -> Int -> Int -> Stream m a -> m ()
666writeSliceRev arr i len s = undefined
667-}