4-- Module : Streamly.Internal.FileSystem.Handle
5-- Copyright : (c) 2018 Composewell Technologies
8-- Maintainer : streamly@composewell.com
9-- Stability : experimental
12-- The fundamental singleton IO APIs are 'getChunk' and 'putChunk' and the
13-- fundamental stream IO APIs built on top of those are
14-- 'readChunksWith' and 'writeChunks'. Rest of this module is just
15-- combinatorial programming using these.
17-- We can achieve line buffering by folding lines in the input stream into a
18-- stream of arrays using Stream.splitOn or Fold.takeEndBy_ and similar
19-- operations. One can wrap the input stream in 'Maybe' type and then use
20-- 'writeMaybesWith' to achieve user controlled buffering.
22-- TODO: Need a separate module for pread/pwrite based reading writing for
23-- seekable devices. Stateless read/write can be helpful in multithreaded
26module Streamly.Internal.FileSystem.Handle
43 -- * Chunked Stream Read
50 -- * Byte Stream Write
51 -- Byte stream write (Folds)
64 -- * Chunked Stream Write
71 -- * Random Access (Seek)
72 -- | Unlike the streaming APIs listed above, these APIs apply to devices or
73 -- files that have random access or seek capability. This type of devices
74 -- include disks, files, memory devices and exclude terminals, pipes,
77 -- We can also generate the request pattern using a funciton.
80 -- , readFrom -- read from a given position to the end of file
81 -- , readFromRev -- read from a given position the beginning of file
82 -- , readTo -- read from beginning up to the given position
83 -- , readToRev -- read from end to the given position in file
89 , readChunksFromToWith
90 -- , readChunksFromThenToWith
93 -- , writeFrom -- start writing at the given position
95 -- , writeTo -- write from beginning up to the given position
101 -- , writeChunksFromTo
102 -- , writeChunksFromToWith
103 -- , writeChunksFromThenToWith
105 , readChunksWithBufferOf
107 , writeChunksWithBufferOf
112import Control.Exception (assert)
113import Control.Monad.IO.Class (MonadIO(..))
114import Data.Function ((&))
115import Data.Maybe (isNothing, fromJust)
116import Data.Word (Word8)
117import Streamly.Internal.Data.Unboxed (Unboxed)
118import System.IO (Handle, SeekMode(..), hGetBufSome, hPutBuf, hSeek)
119import Prelude hiding (read)
121import Streamly.Internal.Data.Fold (Fold)
122import Streamly.Internal.Data.Refold.Type (Refold(..))
123import Streamly.Internal.Data.Unfold.Type (Unfold(..))
124import Streamly.Internal.Data.Array.Unboxed.Type
125 (Array(..), writeNUnsafe, unsafeFreezeWithShrink, byteLength)
126import Streamly.Internal.Data.Stream.Type (Stream)
127import Streamly.Internal.Data.Array.Unboxed.Stream (lpackArraysChunksOf)
128-- import Streamly.String (encodeUtf8, decodeUtf8, foldLines)
129import Streamly.Internal.System.IO (defaultChunkSize)
131import qualified Streamly.Data.Fold as FL
132import qualified Streamly.Data.Array.Unboxed as A
133import qualified Streamly.Internal.Data.Array.Unboxed.Type as A
134import qualified Streamly.Internal.Data.Array.Unboxed.Stream as AS
135import qualified Streamly.Internal.Data.Array.Unboxed.Mut.Type as MArray
136import qualified Streamly.Internal.Data.Refold.Type as Refold
137import qualified Streamly.Internal.Data.Fold.Type as FL(refoldMany)
138import qualified Streamly.Internal.Data.Stream as S
139import qualified Streamly.Internal.Data.Stream.StreamD.Type as D
140 (Stream(..), Step(..))
141import qualified Streamly.Internal.Data.Unfold as UF
142import qualified Streamly.Internal.Data.Stream.StreamK.Type as K (mkStream)
145-- >>> import qualified Streamly.Data.Array.Unboxed as Array
146-- >>> import qualified Streamly.Data.Fold as Fold
147-- >>> import qualified Streamly.Data.Unfold as Unfold
148-- >>> import qualified Streamly.FileSystem.Handle as Handle
149-- >>> import qualified Streamly.Prelude as Stream
151-- >>> import qualified Streamly.Internal.Data.Stream.IsStream as Stream
152-- >>> import qualified Streamly.Internal.Data.Unfold as Unfold (first)
153-- >>> import qualified Streamly.Internal.FileSystem.Handle as Handle
154-- >>> import qualified Streamly.Internal.System.IO as IO (defaultChunkSize)
156-------------------------------------------------------------------------------
158-------------------------------------------------------------------------------
160-- The following references may be useful to build an understanding about the
163-- http://www.linux-mag.com/id/308/ for blocking/non-blocking IO on linux.
164-- https://lwn.net/Articles/612483/ Non-blocking buffered file read operations
165-- https://en.wikipedia.org/wiki/C_file_input/output for C APIs.
166-- https://docs.oracle.com/javase/tutorial/essential/io/file.html for Java API.
167-- https://www.w3.org/TR/FileAPI/ for http file API.
169-------------------------------------------------------------------------------
171-------------------------------------------------------------------------------
173-- | Read a 'ByteArray' consisting of one or more bytes from a file handle. If
174-- no data is available on the handle it blocks until at least one byte becomes
175-- available. If any data is available then it immediately returns that data
176-- without blocking. As a result of this behavior, it may read less than or
177-- equal to the size requested.
180{-# INLINABLE getChunk #-}
181getChunk :: MonadIO m => Int -> Handle -> m (Array Word8)
182getChunk size h = liftIO $ do
183 arr <- MArray.newPinnedBytes size
184 -- ptr <- mallocPlainForeignPtrAlignedBytes size (alignment (undefined :: Word8))
185 MArray.asPtrUnsafe arr $ \p -> do
186 n <- hGetBufSome h p size
187 -- XXX shrink only if the diff is significant
189 unsafeFreezeWithShrink $
190 arr { MArray.arrEnd = n, MArray.arrBound = size }
192-- This could be useful in implementing the "reverse" read APIs or if you want
193-- to read arrays of exact size instead of compacting them later. Compacting
194-- later requires more copying.
196-- | Read a 'ByteArray' consisting of exactly the specified number of bytes
197-- from a file handle.
200{-# INLINABLE getChunkOf #-}
201getChunkOf :: Int -> Handle -> IO (Array Word8)
202getChunkOf = undefined
204-------------------------------------------------------------------------------
205-- Stream of Arrays IO
206-------------------------------------------------------------------------------
208-- | @getChunksWith size h@ reads a stream of arrays from file handle @h@.
209-- The maximum size of a single array is specified by @size@. The actual size
210-- read may be less than or equal to @size@.
212{-# INLINE _getChunksWith #-}
213_getChunksWith :: MonadIO m => Int -> Handle -> Stream m (Array Word8)
214_getChunksWith size h = S.fromStreamK go
216 -- XXX use cons/nil instead
217 go = K.mkStream $ \_ yld _ stp -> do
218 arr <- getChunk size h
219 if byteLength arr == 0
223-- | @getChunksWith size handle@ reads a stream of arrays from the file
224-- handle @handle@. The maximum size of a single array is limited to @size@.
225-- The actual size read may be less than or equal to @size@.
227-- >>> getChunksWith size h = Stream.unfold Handle.readChunksWith (size, h)
230{-# INLINE_NORMAL getChunksWith #-}
231getChunksWith :: MonadIO m => Int -> Handle -> Stream m (Array Word8)
232getChunksWith size h = S.fromStreamD (D.Stream step ())
234 {-# INLINE_LATE step #-}
236 arr <- getChunk size h
238 case byteLength arr of
242-- | Unfold the tuple @(bufsize, handle)@ into a stream of 'Word8' arrays.
243-- Read requests to the IO device are performed using a buffer of size
244-- @bufsize@. The size of an array in the resulting stream is always less than
245-- or equal to @bufsize@.
248{-# INLINE_NORMAL readChunksWith #-}
249readChunksWith :: MonadIO m => Unfold m (Int, Handle) (Array Word8)
251 UF.lmap (uncurry getChunk) UF.repeatM
252 & UF.takeWhile ((/= 0) . byteLength)
255-- | Same as 'readChunksWith'
258{-# DEPRECATED readChunksWithBufferOf "Please use readChunksWith instead." #-}
259{-# INLINE_NORMAL readChunksWithBufferOf #-}
260readChunksWithBufferOf :: MonadIO m => Unfold m (Int, Handle) (Array Word8)
261readChunksWithBufferOf = readChunksWith
263-- There are two ways to implement this.
265-- 1. Idiomatic: use a scan on the output of readChunksWith to total
266-- the array lengths and trim the last array to correct size.
267-- 2. Simply implement it from scratch like readChunksWith.
269-- XXX Change this to readChunksWithFromTo (bufferSize, from, to, h)?
271-- | The input to the unfold is @(from, to, bufferSize, handle)@. It starts
272-- reading from the offset `from` in the file and reads up to the offset `to`.
275{-# INLINE_NORMAL readChunksFromToWith #-}
276readChunksFromToWith :: MonadIO m =>
277 Unfold m (Int, Int, Int, Handle) (Array Word8)
278readChunksFromToWith = Unfold step inject
282 inject (from, to, bufSize, h) = do
283 liftIO $ hSeek h AbsoluteSeek $ fromIntegral from
284 -- XXX Use a strict Tuple?
285 return (to - from + 1, bufSize, h)
287 {-# INLINE_LATE step #-}
288 step (remaining, bufSize, h) =
292 arr <- getChunk (min bufSize remaining) h
294 case byteLength arr of
297 assert (len <= remaining)
298 $ D.Yield arr (remaining - len, bufSize, h)
301-- XXX read 'Array a' instead of Word8
303-- | @getChunks handle@ reads a stream of arrays from the specified file
304-- handle. The maximum size of a single array is limited to
305-- @defaultChunkSize@. The actual size read may be less than or equal to
306-- @defaultChunkSize@.
308-- >>> getChunks = Handle.getChunksWith IO.defaultChunkSize
311{-# INLINE getChunks #-}
312getChunks :: MonadIO m => Handle -> Stream m (Array Word8)
313getChunks = getChunksWith defaultChunkSize
315-- | Unfolds a handle into a stream of 'Word8' arrays. Requests to the IO
316-- device are performed using a buffer of size
317-- 'Streamly.Internal.Data.Array.Unboxed.Type.defaultChunkSize'. The
318-- size of arrays in the resulting stream are therefore less than or equal to
319-- 'Streamly.Internal.Data.Array.Unboxed.Type.defaultChunkSize'.
321-- >>> readChunks = Unfold.first IO.defaultChunkSize Handle.readChunksWith
324{-# INLINE readChunks #-}
325readChunks :: MonadIO m => Unfold m Handle (Array Word8)
326readChunks = UF.first defaultChunkSize readChunksWith
328-------------------------------------------------------------------------------
329-- Read File to Stream
330-------------------------------------------------------------------------------
332-- TODO for concurrent streams implement readahead IO. We can send multiple
333-- read requests at the same time. For serial case we can use async IO. We can
334-- also control the read throughput in mbps or IOPS.
336-- | Unfolds the tuple @(bufsize, handle)@ into a byte stream, read requests
337-- to the IO device are performed using buffers of @bufsize@.
339-- >>> readWith = Unfold.many Array.read Handle.readChunksWith
342{-# INLINE readWith #-}
343readWith :: MonadIO m => Unfold m (Int, Handle) Word8
344readWith = UF.many A.read readChunksWith
346-- | Same as 'readWith'
349{-# DEPRECATED readWithBufferOf "Please use readWith instead." #-}
350{-# INLINE readWithBufferOf #-}
351readWithBufferOf :: MonadIO m => Unfold m (Int, Handle) Word8
352readWithBufferOf = readWith
354-- | @getBytesWith bufsize handle@ reads a byte stream from a file
355-- handle, reads are performed in chunks of up to @bufsize@.
357-- >>> getBytesWith size h = Stream.unfoldMany Array.read $ Handle.getChunksWith size h
360{-# INLINE getBytesWith #-}
361getBytesWith :: MonadIO m => Int -> Handle -> Stream m Word8
362getBytesWith size h = AS.concat $ getChunksWith size h
365-- Generate a stream of elements of the given type from a file 'Handle'.
366-- read :: (MonadIO m, Unboxed a) => Handle -> Stream m a
368-- | Unfolds a file handle into a byte stream. IO requests to the device are
369-- performed in sizes of
370-- 'Streamly.Internal.Data.Array.Unboxed.Type.defaultChunkSize'.
372-- >>> read = Unfold.many Handle.readChunks Array.read
376read :: MonadIO m => Unfold m Handle Word8
377read = UF.many A.read readChunks
379-- | Generate a byte stream from a file 'Handle'.
381-- >>> getBytes h = Stream.unfoldMany Array.read $ Handle.getChunks h
384{-# INLINE getBytes #-}
385getBytes :: MonadIO m => Handle -> Stream m Word8
386getBytes = AS.concat . getChunks
388-------------------------------------------------------------------------------
390-------------------------------------------------------------------------------
392-------------------------------------------------------------------------------
394-------------------------------------------------------------------------------
396-- | Write an 'Array' to a file handle.
399{-# INLINABLE putChunk #-}
400putChunk :: MonadIO m => Handle -> Array a -> m ()
401putChunk _ arr | byteLength arr == 0 = return ()
402putChunk h arr = A.asPtrUnsafe arr $ \ptr ->
403 liftIO $ hPutBuf h ptr aLen
407 -- XXX We should have the length passed by asPtrUnsafe itself.
408 aLen = A.byteLength arr
410-------------------------------------------------------------------------------
411-- Stream of Arrays IO
412-------------------------------------------------------------------------------
414-------------------------------------------------------------------------------
416-------------------------------------------------------------------------------
418-- XXX use an unfold to fromObjects or fromUnfold so that we can put any object
419-- | Write a stream of arrays to a handle.
421-- >>> putChunks h = Stream.mapM_ (Handle.putChunk h)
424{-# INLINE putChunks #-}
425putChunks :: MonadIO m => Handle -> Stream m (Array a) -> m ()
426putChunks h = S.fold (FL.drainBy (putChunk h))
428-- XXX AS.compact can be written idiomatically in terms of foldMany, just like
429-- AS.concat is written in terms of foldMany. Once that is done we can write
430-- idiomatic def in the docs.
432-- | @putChunksWith bufsize handle stream@ writes a stream of arrays
433-- to @handle@ after coalescing the adjacent arrays in chunks of @bufsize@.
434-- The chunk size is only a maximum and the actual writes could be smaller as
435-- we do not split the arrays to fit exactly to the specified size.
438{-# INLINE putChunksWith #-}
439putChunksWith :: (MonadIO m, Unboxed a)
440 => Int -> Handle -> Stream m (Array a) -> m ()
441putChunksWith n h xs = putChunks h $ AS.compact n xs
443-- | @putBytesWith bufsize handle stream@ writes @stream@ to @handle@
444-- in chunks of @bufsize@. A write is performed to the IO device as soon as we
445-- collect the required input size.
447-- >>> putBytesWith n h m = Handle.putChunks h $ Stream.arraysOf n m
450{-# INLINE putBytesWith #-}
451putBytesWith :: MonadIO m => Int -> Handle -> Stream m Word8 -> m ()
452putBytesWith n h m = putChunks h $ S.arraysOf n m
454-- putBytesWith n h m = putChunks h $ AS.arraysOf n m
456-- | Write a byte stream to a file handle. Accumulates the input in chunks of
457-- up to 'Streamly.Internal.Data.Array.Unboxed.Type.defaultChunkSize' before writing.
459-- NOTE: This may perform better than the 'write' fold, you can try this if you
460-- need some extra perf boost.
462-- >>> putBytes = Handle.putBytesWith IO.defaultChunkSize
465{-# INLINE putBytes #-}
466putBytes :: MonadIO m => Handle -> Stream m Word8 -> m ()
467putBytes = putBytesWith defaultChunkSize
469-- | Write a stream of arrays to a handle. Each array in the stream is written
470-- to the device as a separate IO request.
472-- writeChunks h = Fold.drainBy (Handle.putChunk h)
475{-# INLINE writeChunks #-}
476writeChunks :: MonadIO m => Handle -> Fold m (Array a) ()
477writeChunks h = FL.drainBy (putChunk h)
479-- | Like writeChunks but uses the experimental 'Refold' API.
482{-# INLINE consumeChunks #-}
483consumeChunks :: MonadIO m => Refold m Handle (Array a) ()
484consumeChunks = Refold.drainBy putChunk
486-- XXX lpackArraysChunksOf should be written idiomatically
488-- | @writeChunksWith bufsize handle@ writes a stream of arrays
489-- to @handle@ after coalescing the adjacent arrays in chunks of @bufsize@.
490-- We never split an array, if a single array is bigger than the specified size
491-- it emitted as it is. Multiple arrays are coalesed as long as the total size
492-- remains below the specified size.
495{-# INLINE writeChunksWith #-}
496writeChunksWith :: (MonadIO m, Unboxed a)
497 => Int -> Handle -> Fold m (Array a) ()
498writeChunksWith n h = lpackArraysChunksOf n (writeChunks h)
500-- | Same as 'writeChunksWith'
503{-# DEPRECATED writeChunksWithBufferOf "Please use writeChunksWith instead." #-}
504{-# INLINE writeChunksWithBufferOf #-}
505writeChunksWithBufferOf :: (MonadIO m, Unboxed a)
506 => Int -> Handle -> Fold m (Array a) ()
507writeChunksWithBufferOf = writeChunksWith
509-- GHC buffer size dEFAULT_FD_BUFFER_SIZE=8192 bytes.
512-- Note that if you use a chunk size less than 8K (GHC's default buffer
513-- size) then you are advised to use 'NOBuffering' mode on the 'Handle' in case you
514-- do not want buffering to occur at GHC level as well. Same thing applies to
517-- XXX Maybe we should have a Fold.arraysOf like we have Stream.arraysOf
519-- | @writeWith reqSize handle@ writes the input stream to @handle@.
520-- Bytes in the input stream are collected into a buffer until we have a chunk
521-- of @reqSize@ and then written to the IO device.
523-- >>> writeWith n h = Fold.chunksOf n (Array.writeNUnsafe n) (Handle.writeChunks h)
526{-# INLINE writeWith #-}
527writeWith :: MonadIO m => Int -> Handle -> Fold m Word8 ()
528writeWith n h = FL.chunksOf n (writeNUnsafe n) (writeChunks h)
530-- | Same as 'writeWith'
533{-# DEPRECATED writeWithBufferOf "Please use writeWith instead." #-}
534{-# INLINE writeWithBufferOf #-}
535writeWithBufferOf :: MonadIO m => Int -> Handle -> Fold m Word8 ()
536writeWithBufferOf = writeWith
538-- | Write a stream of 'Maybe' values. Keep buffering the just values in an
539-- array until a 'Nothing' is encountered or the buffer size exceeds the
540-- specified limit, at that point flush the buffer to the handle.
543{-# INLINE writeMaybesWith #-}
544writeMaybesWith :: (MonadIO m )
545 => Int -> Handle -> Fold m (Maybe Word8) ()
547 let writeNJusts = FL.lmap fromJust $ A.writeN n
548 writeOnNothing = FL.takeEndBy_ isNothing writeNJusts
549 in FL.many writeOnNothing (writeChunks h)
551-- | Like 'writeWith' but uses the experimental 'Refold' API.
554{-# INLINE consumerWith #-}
555consumerWith :: MonadIO m => Int -> Refold m Handle Word8 ()
557 FL.refoldMany (FL.take n $ writeNUnsafe n) consumeChunks
559-- | Write a byte stream to a file handle. Accumulates the input in chunks of
560-- up to 'Streamly.Internal.Data.Array.Unboxed.Type.defaultChunkSize' before writing
563-- >>> write = Handle.writeWith IO.defaultChunkSize
567write :: MonadIO m => Handle -> Fold m Word8 ()
568write = writeWith defaultChunkSize
570-- | Like 'write' but uses the experimental 'Refold' API.
573{-# INLINE consumer #-}
574consumer :: MonadIO m => Refold m Handle Word8 ()
575consumer = consumerWith defaultChunkSize
579write :: (MonadIO m, Unboxed a) => Handle -> Stream m a -> m ()
580write = toHandleWith A.defaultChunkSize
583-- XXX mmap a file into an array. This could be useful for in-place operations
584-- on a file. For example, we can quicksort the contents of a file by mmapping
587-------------------------------------------------------------------------------
588-- IO with encoding/decoding Unicode characters
589-------------------------------------------------------------------------------
593-- > readUtf8 = decodeUtf8 . read
595-- Read a UTF8 encoded stream of unicode characters from a file handle.
598{-# INLINE readUtf8 #-}
599readUtf8 :: MonadIO m => Handle -> Stream m Char
600readUtf8 = decodeUtf8 . read
603-- > writeUtf8 h s = write h $ encodeUtf8 s
605-- Encode a stream of unicode characters to UTF8 and write it to the given file
606-- handle. Default block buffering applies to the writes.
609{-# INLINE writeUtf8 #-}
610writeUtf8 :: MonadIO m => Handle -> Stream m Char -> m ()
611writeUtf8 h s = write h $ encodeUtf8 s
613-- | Write a stream of unicode characters after encoding to UTF-8 in chunks
614-- separated by a linefeed character @'\n'@. If the size of the buffer exceeds
615-- @defaultChunkSize@ and a linefeed is not yet found, the buffer is written
616-- anyway. This is similar to writing to a 'Handle' with the 'LineBuffering'
620{-# INLINE writeUtf8ByLines #-}
621writeUtf8ByLines :: MonadIO m => Handle -> Stream m Char -> m ()
622writeUtf8ByLines = undefined
624-- | Read UTF-8 lines from a file handle and apply the specified fold to each
625-- line. This is similar to reading a 'Handle' with the 'LineBuffering' option.
628{-# INLINE readLines #-}
629readLines :: MonadIO m => Handle -> Fold m Char b -> Stream m b
630readLines h f = foldLines (readUtf8 h) f
632-------------------------------------------------------------------------------
633-- Framing on a sequence
634-------------------------------------------------------------------------------
636-- | Read a stream from a file handle and split it into frames delimited by
637-- the specified sequence of elements. The supplied fold is applied on each
641{-# INLINE readFrames #-}
642readFrames :: (MonadIO m, Unboxed a)
643 => Array a -> Handle -> Fold m a b -> Stream m b
644readFrames = undefined -- foldFrames . read
646-- | Write a stream to the given file handle buffering up to frames separated
647-- by the given sequence or up to a maximum of @defaultChunkSize@.
650{-# INLINE writeByFrames #-}
651writeByFrames :: (MonadIO m, Unboxed a)
652 => Array a -> Handle -> Stream m a -> m ()
653writeByFrames = undefined
655-------------------------------------------------------------------------------
657-------------------------------------------------------------------------------
659-- | Write collecting the input in sessions of n seconds or if chunkSize
661{-# INLINE writeByChunksOrSessionsOf #-}
662writeByChunksOrSessionsOf :: MonadIO m
663 => Int -> Double -> Handle -> Stream m Word8 -> m ()
664writeByChunksOrSessionsOf chunkSize sessionSize h m = undefined
666-- | Write collecting the input in sessions of n seconds or if defaultChunkSize
668{-# INLINE writeBySessionsOf #-}
669writeBySessionsOf :: MonadIO m => Double -> Handle -> Stream m Word8 -> m ()
670writeBySessionsOf n = writeByChunksOrSessionsOf defaultChunkSize n
672-------------------------------------------------------------------------------
673-- Random Access IO (Seek)
674-------------------------------------------------------------------------------
676-- XXX handles could be shared, so we may not want to use the handle state at
677-- all for these APIs. we can use pread and pwrite instead. On windows we will
678-- need to use readFile/writeFile with an offset argument.
680-------------------------------------------------------------------------------
682-- | Read the element at the given index treating the file as an array.
685{-# INLINE readIndex #-}
686readIndex :: Unboxed a => Handle -> Int -> Maybe a
687readIndex arr i = undefined
689-- NOTE: To represent a range to read we have chosen (start, size) instead of
690-- (start, end). This helps in removing the ambiguity of whether "end" is
691-- included in the range or not.
693-- We could avoid specifying the range to be read and instead use "take size"
694-- on the stream, but it may end up reading more and then consume it partially.
696-- | @readSliceWith chunkSize handle pos len@ reads up to @len@ bytes
697-- from @handle@ starting at the offset @pos@ from the beginning of the file.
699-- Reads are performed in chunks of size @chunkSize@. For block devices, to
700-- avoid reading partial blocks @chunkSize@ must align with the block size of
701-- the underlying device. If the underlying block size is unknown, it is a good
702-- idea to keep it a multiple 4KiB. This API ensures that the start of each
703-- chunk is aligned with @chunkSize@ from second chunk onwards.
705{-# INLINE readSliceWith #-}
706readSliceWith :: (MonadIO m, Unboxed a)
707 => Int -> Handle -> Int -> Int -> Stream m a
708readSliceWith chunkSize h pos len = undefined
710-- | @readSlice h i count@ streams a slice from the file handle @h@ starting
711-- at index @i@ and reading up to @count@ elements in the forward direction
712-- ending at the index @i + count - 1@.
715{-# INLINE readSlice #-}
716readSlice :: (MonadIO m, Unboxed a)
717 => Handle -> Int -> Int -> Stream m a
718readSlice = readSliceWith A.defaultChunkSize
720-- | @readSliceRev h i count@ streams a slice from the file handle @h@ starting
721-- at index @i@ and reading up to @count@ elements in the reverse direction
722-- ending at the index @i - count + 1@.
725{-# INLINE readSliceRev #-}
726readSliceRev :: (MonadIO m, Unboxed a)
727 => Handle -> Int -> Int -> Stream m a
728readSliceRev h i count = undefined
730-- | Write the given element at the given index in the file.
733{-# INLINE writeIndex #-}
734writeIndex :: (MonadIO m, Unboxed a) => Handle -> Int -> a -> m ()
735writeIndex h i a = undefined
737-- | @writeSlice h i count stream@ writes a stream to the file handle @h@
738-- starting at index @i@ and writing up to @count@ elements in the forward
739-- direction ending at the index @i + count - 1@.
742{-# INLINE writeSlice #-}
743writeSlice :: (Monad m, Unboxed a)
744 => Handle -> Int -> Int -> Stream m a -> m ()
745writeSlice h i len s = undefined
747-- | @writeSliceRev h i count stream@ writes a stream to the file handle @h@
748-- starting at index @i@ and writing up to @count@ elements in the reverse
749-- direction ending at the index @i - count + 1@.
752{-# INLINE writeSliceRev #-}
753writeSliceRev :: (Monad m, Unboxed a)
754 => Handle -> Int -> Int -> Stream m a -> m ()
755writeSliceRev arr i len s = undefined
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list