on 291ff37 help sign in
646 lines 24 kB history raw
1{-# OPTIONS_HADDOCK hide #-}
2{-# LANGUAGE CPP #-}
3{-# LANGUAGE BangPatterns #-}
4{-# LANGUAGE FlexibleContexts #-}
5{-# LANGUAGE MagicHash #-}
6{-# LANGUAGE RecordWildCards #-}
7{-# LANGUAGE UnboxedTuples #-}
9#include "inline.hs"
11-- |
12-- Module : Streamly.Internal.FileSystem.Handle
13-- Copyright : (c) 2018 Composewell Technologies
14--
15-- License : BSD3
16-- Maintainer : streamly@composewell.com
17-- Stability : experimental
18-- Portability : GHC
20module Streamly.Internal.FileSystem.Handle
21 (
22 -- ** Read from Handle
23 read
24 -- , readUtf8
25 -- , readLines
26 -- , readFrames
27 , readWithBufferOf
29 , toBytes
30 , toBytesWithBufferOf
31 , getBytes
33 -- -- * Array Read
34 -- , readArrayUpto
35 -- , readArrayOf
36 , readChunks
37 , readChunksWithBufferOf
39 , toChunksWithBufferOf
40 , toChunks
41 , getChunks
43 -- ** Write to Handle
44 -- Byte stream write (Folds)
45 , write
46 , write2
47 -- , writeUtf8
48 -- , writeUtf8ByLines
49 -- , writeByFrames
50 -- , writeLines
51 , writeWithBufferOf
53 -- Byte stream write (Streams)
54 , fromBytes
55 , fromBytesWithBufferOf
57 -- -- * Array Write
58 , writeArray
59 , writeChunks
60 , writeChunksWithBufferOf
62 -- -- * Array stream Write
63 , fromChunksWithBufferOf
64 , fromChunks
65 , putChunks
66 , putStrings
67 -- , putLines
69 -- -- * Random Access (Seek)
70 -- -- | Unlike the streaming APIs listed above, these APIs apply to devices or
71 -- files that have random access or seek capability. This type of devices
72 -- include disks, files, memory devices and exclude terminals, pipes,
73 -- sockets and fifos.
74 --
75 -- XXX need to decide whether to use readFromStepN style or readFromThenTo
76 -- style. The latter is consistent with list enumeration. The former may be
77 -- more unambiguous and it is easier and clearer to specify 0 elements.
78 --
79 -- We can also generate the request pattern using a funciton.
80 --
81 -- , readIndex
82 -- , readFrom -- read from a given position to the end of file
83 -- , readFromRev -- read from a given position the beginning of file
84 -- , readTo -- read from beginning up to the given position
85 -- , readToRev -- read from end to the given position in file
86 -- , readFromTo
87 -- , readFromThenTo
89 -- , readChunksFrom
90 -- , readChunksFromTo
91 -- , readChunksFromToWithBufferOf
92 -- , readChunksFromThenToWithBufferOf
94 -- , writeIndex
95 -- , writeFrom -- start writing at the given position
96 -- , writeFromRev
97 -- , writeTo -- write from beginning up to the given position
98 -- , writeToRev
99 -- , writeFromTo
100 -- , writeFromThenTo
101 --
102 -- , writeChunksFrom
103 -- , writeChunksFromTo
104 -- , writeChunksFromToWithBufferOf
105 -- , writeChunksFromThenToWithBufferOf
106 )
107where
109import Control.Monad.IO.Class (MonadIO(..))
110import Data.Word (Word8)
111import Foreign.ForeignPtr (withForeignPtr)
112import Foreign.ForeignPtr.Unsafe (unsafeForeignPtrToPtr)
113import Foreign.Ptr (minusPtr, plusPtr)
114import Foreign.Storable (Storable(..))
115import GHC.ForeignPtr (mallocPlainForeignPtrBytes)
116import System.IO (Handle, hGetBufSome, hPutBuf, stdin, stdout)
117import Prelude hiding (read)
119import Streamly (MonadAsync)
120import Streamly.Data.Fold (Fold)
121import Streamly.Internal.Data.Fold.Types (Fold2(..))
122import Streamly.Internal.Data.Unfold.Types (Unfold(..))
123import Streamly.Internal.Memory.Array.Types
124 (Array(..), writeNUnsafe, defaultChunkSize, shrinkToFit,
125 lpackArraysChunksOf)
126import Streamly.Streams.Serial (SerialT)
127import Streamly.Streams.StreamK.Type (IsStream, mkStream)
128-- import Streamly.String (encodeUtf8, decodeUtf8, foldLines)
130import qualified Streamly.Data.Fold as FL
131import qualified Streamly.Internal.Data.Fold.Types as FL
132import qualified Streamly.Internal.Data.Unicode.Stream as U
133import qualified Streamly.Internal.Data.Unfold as UF
134import qualified Streamly.Internal.Memory.Array as IA
135import qualified Streamly.Internal.Memory.ArrayStream as AS
136import qualified Streamly.Internal.Prelude as S
137import qualified Streamly.Memory.Array as A
138import qualified Streamly.Internal.Data.Stream.StreamD.Type as D
140-------------------------------------------------------------------------------
141-- References
142-------------------------------------------------------------------------------
143--
144-- The following references may be useful to build an understanding about the
145-- file API design:
146--
147-- http://www.linux-mag.com/id/308/ for blocking/non-blocking IO on linux.
148-- https://lwn.net/Articles/612483/ Non-blocking buffered file read operations
149-- https://en.wikipedia.org/wiki/C_file_input/output for C APIs.
150-- https://docs.oracle.com/javase/tutorial/essential/io/file.html for Java API.
151-- https://www.w3.org/TR/FileAPI/ for http file API.
153-------------------------------------------------------------------------------
154-- Array IO (Input)
155-------------------------------------------------------------------------------
157-- | Read a 'ByteArray' from a file handle. If no data is available on the
158-- handle it blocks until some data becomes available. If data is available
159-- then it immediately returns that data without blocking. It reads a maximum
160-- of up to the size requested.
161{-# INLINABLE readArrayUpto #-}
162readArrayUpto :: Int -> Handle -> IO (Array Word8)
163readArrayUpto size h = do
164 ptr <- mallocPlainForeignPtrBytes size
165 -- ptr <- mallocPlainForeignPtrAlignedBytes size (alignment (undefined :: Word8))
166 withForeignPtr ptr $ \p -> do
167 n <- hGetBufSome h p size
168 let v = Array
169 { aStart = ptr
170 , aEnd = p `plusPtr` n
171 , aBound = p `plusPtr` size
172 }
173 -- XXX shrink only if the diff is significant
174 shrinkToFit v
176-------------------------------------------------------------------------------
177-- Stream of Arrays IO
178-------------------------------------------------------------------------------
180-- | @toChunksWithBufferOf size h@ reads a stream of arrays from file handle @h@.
181-- The maximum size of a single array is specified by @size@. The actual size
182-- read may be less than or equal to @size@.
183{-# INLINABLE _toChunksWithBufferOf #-}
184_toChunksWithBufferOf :: (IsStream t, MonadIO m)
185 => Int -> Handle -> t m (Array Word8)
186_toChunksWithBufferOf size h = go
187 where
188 -- XXX use cons/nil instead
189 go = mkStream $ \_ yld _ stp -> do
190 arr <- liftIO $ readArrayUpto size h
191 if A.length arr == 0
192 then stp
193 else yld arr go
195-- | @toChunksWithBufferOf size handle@ reads a stream of arrays from the file
196-- handle @handle@. The maximum size of a single array is limited to @size@.
197-- The actual size read may be less than or equal to @size@.
198--
199-- @since 0.7.0
200{-# INLINE_NORMAL toChunksWithBufferOf #-}
201toChunksWithBufferOf :: (IsStream t, MonadIO m) => Int -> Handle -> t m (Array Word8)
202toChunksWithBufferOf size h = D.fromStreamD (D.Stream step ())
203 where
204 {-# INLINE_LATE step #-}
205 step _ _ = do
206 arr <- liftIO $ readArrayUpto size h
207 return $
208 case A.length arr of
209 0 -> D.Stop
210 _ -> D.Yield arr ()
212-- | Unfold the tuple @(bufsize, handle)@ into a stream of 'Word8' arrays.
213-- Read requests to the IO device are performed using a buffer of size
214-- @bufsize@. The size of an array in the resulting stream is always less than
215-- or equal to @bufsize@.
216--
217-- @since 0.7.0
218{-# INLINE_NORMAL readChunksWithBufferOf #-}
219readChunksWithBufferOf :: MonadIO m => Unfold m (Int, Handle) (Array Word8)
220readChunksWithBufferOf = Unfold step return
221 where
222 {-# INLINE_LATE step #-}
223 step (size, h) = do
224 arr <- liftIO $ readArrayUpto size h
225 return $
226 case A.length arr of
227 0 -> D.Stop
228 _ -> D.Yield arr (size, h)
230-- XXX read 'Array a' instead of Word8
231--
232-- | @toChunks handle@ reads a stream of arrays from the specified file
233-- handle. The maximum size of a single array is limited to
234-- @defaultChunkSize@. The actual size read may be less than or equal to
235-- @defaultChunkSize@.
236--
237-- > toChunks = toChunksWithBufferOf defaultChunkSize
238--
239-- @since 0.7.0
240{-# INLINE toChunks #-}
241toChunks :: (IsStream t, MonadIO m) => Handle -> t m (Array Word8)
242toChunks = toChunksWithBufferOf defaultChunkSize
244-- | Read a stream of chunks from standard input. The maximum size of a single
245-- chunk is limited to @defaultChunkSize@. The actual size read may be less
246-- than @defaultChunkSize@.
247--
248-- > getChunks = toChunks stdin
249--
250-- /Internal/
251--
252{-# INLINE getChunks #-}
253getChunks :: (IsStream t, MonadIO m) => t m (Array Word8)
254getChunks = toChunks stdin
256-- | Read a stream of bytes from standard input.
257--
258-- > getBytes = toBytes stdin
259--
260-- /Internal/
261--
262{-# INLINE getBytes #-}
263getBytes :: (IsStream t, MonadIO m) => t m Word8
264getBytes = toBytes stdin
266-- | Unfolds a handle into a stream of 'Word8' arrays. Requests to the IO
267-- device are performed using a buffer of size
268-- 'Streamly.Internal.Memory.Array.Types.defaultChunkSize'. The
269-- size of arrays in the resulting stream are therefore less than or equal to
270-- 'Streamly.Internal.Memory.Array.Types.defaultChunkSize'.
271--
272-- @since 0.7.0
273{-# INLINE readChunks #-}
274readChunks :: MonadIO m => Unfold m Handle (Array Word8)
275readChunks = UF.supplyFirst readChunksWithBufferOf defaultChunkSize
277-------------------------------------------------------------------------------
278-- Read File to Stream
279-------------------------------------------------------------------------------
281-- TODO for concurrent streams implement readahead IO. We can send multiple
282-- read requests at the same time. For serial case we can use async IO. We can
283-- also control the read throughput in mbps or IOPS.
285-- | Unfolds the tuple @(bufsize, handle)@ into a byte stream, read requests
286-- to the IO device are performed using buffers of @bufsize@.
287--
288-- @since 0.7.0
289{-# INLINE readWithBufferOf #-}
290readWithBufferOf :: MonadIO m => Unfold m (Int, Handle) Word8
291readWithBufferOf = UF.concat readChunksWithBufferOf A.read
293-- | @toBytesWithBufferOf bufsize handle@ reads a byte stream from a file
294-- handle, reads are performed in chunks of up to @bufsize@.
295--
296-- /Internal/
297{-# INLINE toBytesWithBufferOf #-}
298toBytesWithBufferOf :: (IsStream t, MonadIO m) => Int -> Handle -> t m Word8
299toBytesWithBufferOf chunkSize h = AS.concat $ toChunksWithBufferOf chunkSize h
301-- TODO
302-- Generate a stream of elements of the given type from a file 'Handle'.
303-- read :: (IsStream t, MonadIO m, Storable a) => Handle -> t m a
304--
305-- | Unfolds a file handle into a byte stream. IO requests to the device are
306-- performed in sizes of
307-- 'Streamly.Internal.Memory.Array.Types.defaultChunkSize'.
308--
309-- @since 0.7.0
310{-# INLINE read #-}
311read :: MonadIO m => Unfold m Handle Word8
312read = UF.supplyFirst readWithBufferOf defaultChunkSize
314-- | Generate a byte stream from a file 'Handle'.
315--
316-- /Internal/
317{-# INLINE toBytes #-}
318toBytes :: (IsStream t, MonadIO m) => Handle -> t m Word8
319toBytes = AS.concat . toChunks
321-------------------------------------------------------------------------------
322-- Writing
323-------------------------------------------------------------------------------
325-------------------------------------------------------------------------------
326-- Array IO (output)
327-------------------------------------------------------------------------------
329-- | Write an 'Array' to a file handle.
330--
331-- @since 0.7.0
332{-# INLINABLE writeArray #-}
333writeArray :: Storable a => Handle -> Array a -> IO ()
334writeArray _ arr | A.length arr == 0 = return ()
335writeArray h Array{..} = withForeignPtr aStart $ \p -> hPutBuf h p aLen
336 where
337 aLen =
338 let p = unsafeForeignPtrToPtr aStart
339 in aEnd `minusPtr` p
341-------------------------------------------------------------------------------
342-- Stream of Arrays IO
343-------------------------------------------------------------------------------
345-------------------------------------------------------------------------------
346-- Writing
347-------------------------------------------------------------------------------
349-- | Write a stream of arrays to a handle.
350--
351-- @since 0.7.0
352{-# INLINE fromChunks #-}
353fromChunks :: (MonadIO m, Storable a)
354 => Handle -> SerialT m (Array a) -> m ()
355fromChunks h m = S.mapM_ (liftIO . writeArray h) m
357-- | Write a stream of chunks to standard output.
358--
359-- /Internal/
360--
361{-# INLINE putChunks #-}
362putChunks :: (MonadIO m, Storable a) => SerialT m (Array a) -> m ()
363putChunks = fromChunks stdout
365-- | Write a stream of strings to standard output using Latin1 encoding.
366--
367-- /Internal/
368--
369{-# INLINE putStrings #-}
370putStrings :: MonadAsync m => SerialT m String -> m ()
371putStrings = putChunks . S.mapM (IA.fromStream . U.encodeLatin1 . S.fromList)
373-- | @fromChunksWithBufferOf bufsize handle stream@ writes a stream of arrays
374-- to @handle@ after coalescing the adjacent arrays in chunks of @bufsize@.
375-- The chunk size is only a maximum and the actual writes could be smaller as
376-- we do not split the arrays to fit exactly to the specified size.
377--
378-- @since 0.7.0
379{-# INLINE fromChunksWithBufferOf #-}
380fromChunksWithBufferOf :: (MonadIO m, Storable a)
381 => Int -> Handle -> SerialT m (Array a) -> m ()
382fromChunksWithBufferOf n h xs = fromChunks h $ AS.compact n xs
384-- | @fromBytesWithBufferOf bufsize handle stream@ writes @stream@ to @handle@
385-- in chunks of @bufsize@. A write is performed to the IO device as soon as we
386-- collect the required input size.
387--
388-- @since 0.7.0
389{-# INLINE fromBytesWithBufferOf #-}
390fromBytesWithBufferOf :: MonadIO m => Int -> Handle -> SerialT m Word8 -> m ()
391fromBytesWithBufferOf n h m = fromChunks h $ S.arraysOf n m
392-- fromBytesWithBufferOf n h m = fromChunks h $ AS.arraysOf n m
394-- > write = 'writeWithBufferOf' A.defaultChunkSize
395--
396-- | Write a byte stream to a file handle. Accumulates the input in chunks of
397-- up to 'Streamly.Internal.Memory.Array.Types.defaultChunkSize' before writing.
398--
399-- NOTE: This may perform better than the 'write' fold, you can try this if you
400-- need some extra perf boost.
401--
402-- @since 0.7.0
403{-# INLINE fromBytes #-}
404fromBytes :: MonadIO m => Handle -> SerialT m Word8 -> m ()
405fromBytes = fromBytesWithBufferOf defaultChunkSize
407-- | Write a stream of arrays to a handle. Each array in the stream is written
408-- to the device as a separate IO request.
409--
410-- @since 0.7.0
411{-# INLINE writeChunks #-}
412writeChunks :: (MonadIO m, Storable a) => Handle -> Fold m (Array a) ()
413writeChunks h = FL.drainBy (liftIO . writeArray h)
415{-# INLINE writeChunks2 #-}
416writeChunks2 :: (MonadIO m, Storable a) => Fold2 m Handle (Array a) ()
417writeChunks2 = Fold2 (\h arr -> liftIO $ writeArray h arr >> return h) return (\_ -> return ())
419-- | @writeChunksWithBufferOf bufsize handle@ writes a stream of arrays
420-- to @handle@ after coalescing the adjacent arrays in chunks of @bufsize@.
421-- We never split an array, if a single array is bigger than the specified size
422-- it emitted as it is. Multiple arrays are coalesed as long as the total size
423-- remains below the specified size.
424--
425-- @since 0.7.0
426{-# INLINE writeChunksWithBufferOf #-}
427writeChunksWithBufferOf :: (MonadIO m, Storable a)
428 => Int -> Handle -> Fold m (Array a) ()
429writeChunksWithBufferOf n h = lpackArraysChunksOf n (writeChunks h)
431-- GHC buffer size dEFAULT_FD_BUFFER_SIZE=8192 bytes.
432--
433-- XXX test this
434-- Note that if you use a chunk size less than 8K (GHC's default buffer
435-- size) then you are advised to use 'NOBuffering' mode on the 'Handle' in case you
436-- do not want buffering to occur at GHC level as well. Same thing applies to
437-- writes as well.
439-- | @writeWithBufferOf reqSize handle@ writes the input stream to @handle@.
440-- Bytes in the input stream are collected into a buffer until we have a chunk
441-- of @reqSize@ and then written to the IO device.
442--
443-- @since 0.7.0
444{-# INLINE writeWithBufferOf #-}
445writeWithBufferOf :: MonadIO m => Int -> Handle -> Fold m Word8 ()
446writeWithBufferOf n h = FL.lchunksOf n (writeNUnsafe n) (writeChunks h)
448{-# INLINE writeWithBufferOf2 #-}
449writeWithBufferOf2 :: MonadIO m => Int -> Fold2 m Handle Word8 ()
450writeWithBufferOf2 n = FL.lchunksOf2 n (writeNUnsafe n) writeChunks2
452-- > write = 'writeWithBufferOf' A.defaultChunkSize
453--
454-- | Write a byte stream to a file handle. Accumulates the input in chunks of
455-- up to 'Streamly.Internal.Memory.Array.Types.defaultChunkSize' before writing
456-- to the IO device.
457--
458-- @since 0.7.0
459{-# INLINE write #-}
460write :: MonadIO m => Handle -> Fold m Word8 ()
461write = writeWithBufferOf defaultChunkSize
463{-# INLINE write2 #-}
464write2 :: MonadIO m => Fold2 m Handle Word8 ()
465write2 = writeWithBufferOf2 defaultChunkSize
467{-
468{-# INLINE write #-}
469write :: (MonadIO m, Storable a) => Handle -> SerialT m a -> m ()
470write = toHandleWith A.defaultChunkSize
471-}
473-- XXX mmap a file into an array. This could be useful for in-place operations
474-- on a file. For example, we can quicksort the contents of a file by mmapping
475-- it.
477-------------------------------------------------------------------------------
478-- IO with encoding/decoding Unicode characters
479-------------------------------------------------------------------------------
481{-
482-- |
483-- > readUtf8 = decodeUtf8 . read
484--
485-- Read a UTF8 encoded stream of unicode characters from a file handle.
486--
487-- @since 0.7.0
488{-# INLINE readUtf8 #-}
489readUtf8 :: (IsStream t, MonadIO m) => Handle -> t m Char
490readUtf8 = decodeUtf8 . read
492-- |
493-- > writeUtf8 h s = write h $ encodeUtf8 s
494--
495-- Encode a stream of unicode characters to UTF8 and write it to the given file
496-- handle. Default block buffering applies to the writes.
497--
498-- @since 0.7.0
499{-# INLINE writeUtf8 #-}
500writeUtf8 :: MonadIO m => Handle -> SerialT m Char -> m ()
501writeUtf8 h s = write h $ encodeUtf8 s
503-- | Write a stream of unicode characters after encoding to UTF-8 in chunks
504-- separated by a linefeed character @'\n'@. If the size of the buffer exceeds
505-- @defaultChunkSize@ and a linefeed is not yet found, the buffer is written
506-- anyway. This is similar to writing to a 'Handle' with the 'LineBuffering'
507-- option.
508--
509-- @since 0.7.0
510{-# INLINE writeUtf8ByLines #-}
511writeUtf8ByLines :: (IsStream t, MonadIO m) => Handle -> t m Char -> m ()
512writeUtf8ByLines = undefined
514-- | Read UTF-8 lines from a file handle and apply the specified fold to each
515-- line. This is similar to reading a 'Handle' with the 'LineBuffering' option.
516--
517-- @since 0.7.0
518{-# INLINE readLines #-}
519readLines :: (IsStream t, MonadIO m) => Handle -> Fold m Char b -> t m b
520readLines h f = foldLines (readUtf8 h) f
522-------------------------------------------------------------------------------
523-- Framing on a sequence
524-------------------------------------------------------------------------------
526-- | Read a stream from a file handle and split it into frames delimited by
527-- the specified sequence of elements. The supplied fold is applied on each
528-- frame.
529--
530-- @since 0.7.0
531{-# INLINE readFrames #-}
532readFrames :: (IsStream t, MonadIO m, Storable a)
533 => Array a -> Handle -> Fold m a b -> t m b
534readFrames = undefined -- foldFrames . read
536-- | Write a stream to the given file handle buffering up to frames separated
537-- by the given sequence or up to a maximum of @defaultChunkSize@.
538--
539-- @since 0.7.0
540{-# INLINE writeByFrames #-}
541writeByFrames :: (IsStream t, MonadIO m, Storable a)
542 => Array a -> Handle -> t m a -> m ()
543writeByFrames = undefined
545-------------------------------------------------------------------------------
546-- Framing by time
547-------------------------------------------------------------------------------
549-- | Write collecting the input in sessions of n seconds or if chunkSize
550-- gets exceeded.
551{-# INLINE writeByChunksOrSessionsOf #-}
552writeByChunksOrSessionsOf :: MonadIO m
553 => Int -> Double -> Handle -> SerialT m Word8 -> m ()
554writeByChunksOrSessionsOf chunkSize sessionSize h m = undefined
556-- | Write collecting the input in sessions of n seconds or if defaultChunkSize
557-- gets exceeded.
558{-# INLINE writeBySessionsOf #-}
559writeBySessionsOf :: MonadIO m => Double -> Handle -> SerialT m Word8 -> m ()
560writeBySessionsOf n = writeByChunksOrSessionsOf defaultChunkSize n
562-------------------------------------------------------------------------------
563-- Random Access IO (Seek)
564-------------------------------------------------------------------------------
566-- XXX handles could be shared, so we may not want to use the handle state at
567-- all for these APIs. we can use pread and pwrite instead. On windows we will
568-- need to use readFile/writeFile with an offset argument.
570-------------------------------------------------------------------------------
572-- | Read the element at the given index treating the file as an array.
573--
574-- @since 0.7.0
575{-# INLINE readIndex #-}
576readIndex :: Storable a => Handle -> Int -> Maybe a
577readIndex arr i = undefined
579-- NOTE: To represent a range to read we have chosen (start, size) instead of
580-- (start, end). This helps in removing the ambiguity of whether "end" is
581-- included in the range or not.
582--
583-- We could avoid specifying the range to be read and instead use "take size"
584-- on the stream, but it may end up reading more and then consume it partially.
586-- | @readSliceWith chunkSize handle pos len@ reads up to @len@ bytes
587-- from @handle@ starting at the offset @pos@ from the beginning of the file.
588--
589-- Reads are performed in chunks of size @chunkSize@. For block devices, to
590-- avoid reading partial blocks @chunkSize@ must align with the block size of
591-- the underlying device. If the underlying block size is unknown, it is a good
592-- idea to keep it a multiple 4KiB. This API ensures that the start of each
593-- chunk is aligned with @chunkSize@ from second chunk onwards.
594--
595{-# INLINE readSliceWith #-}
596readSliceWith :: (IsStream t, MonadIO m, Storable a)
597 => Int -> Handle -> Int -> Int -> t m a
598readSliceWith chunkSize h pos len = undefined
600-- | @readSlice h i count@ streams a slice from the file handle @h@ starting
601-- at index @i@ and reading up to @count@ elements in the forward direction
602-- ending at the index @i + count - 1@.
603--
604-- @since 0.7.0
605{-# INLINE readSlice #-}
606readSlice :: (IsStream t, MonadIO m, Storable a)
607 => Handle -> Int -> Int -> t m a
608readSlice = readSliceWith A.defaultChunkSize
610-- | @readSliceRev h i count@ streams a slice from the file handle @h@ starting
611-- at index @i@ and reading up to @count@ elements in the reverse direction
612-- ending at the index @i - count + 1@.
613--
614-- @since 0.7.0
615{-# INLINE readSliceRev #-}
616readSliceRev :: (IsStream t, MonadIO m, Storable a)
617 => Handle -> Int -> Int -> t m a
618readSliceRev h i count = undefined
620-- | Write the given element at the given index in the file.
621--
622-- @since 0.7.0
623{-# INLINE writeIndex #-}
624writeIndex :: (MonadIO m, Storable a) => Handle -> Int -> a -> m ()
625writeIndex h i a = undefined
627-- | @writeSlice h i count stream@ writes a stream to the file handle @h@
628-- starting at index @i@ and writing up to @count@ elements in the forward
629-- direction ending at the index @i + count - 1@.
630--
631-- @since 0.7.0
632{-# INLINE writeSlice #-}
633writeSlice :: (IsStream t, Monad m, Storable a)
634 => Handle -> Int -> Int -> t m a -> m ()
635writeSlice h i len s = undefined
637-- | @writeSliceRev h i count stream@ writes a stream to the file handle @h@
638-- starting at index @i@ and writing up to @count@ elements in the reverse
639-- direction ending at the index @i - count + 1@.
640--
641-- @since 0.7.0
642{-# INLINE writeSliceRev #-}
643writeSliceRev :: (IsStream t, Monad m, Storable a)
644 => Handle -> Int -> Int -> t m a -> m ()
645writeSliceRev arr i len s = undefined
646-}