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
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 , chunkReaderFromToWith
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
106 , readChunksWithBufferOf
108 , writeChunksWithBufferOf
113import Control.Exception (assert)
114import Control.Monad.IO.Class (MonadIO(..))
115import Data.Function ((&))
116import Data.Maybe (isNothing, fromJust)
117import Data.Word (Word8)
118import Streamly.Internal.Data.Unbox (Unbox)
119import System.IO (Handle, SeekMode(..), hGetBufSome, hPutBuf, hSeek)
120import Prelude hiding (read)
122import Streamly.Internal.Data.Fold (Fold)
123import Streamly.Internal.Data.Refold.Type (Refold(..))
124import Streamly.Internal.Data.Unfold.Type (Unfold(..))
125import Streamly.Internal.Data.Array.Type
126 (Array(..), pinnedWriteNUnsafe, unsafeFreezeWithShrink, byteLength)
127import Streamly.Internal.Data.Stream.StreamD.Type (Stream)
128import Streamly.Internal.Data.Stream.Chunked (lpackArraysChunksOf)
129-- import Streamly.String (encodeUtf8, decodeUtf8, foldLines)
130import Streamly.Internal.System.IO (defaultChunkSize)
132import qualified Streamly.Data.Fold as FL
133import qualified Streamly.Data.Array as A
134import qualified Streamly.Internal.Data.Array.Type as A
135import qualified Streamly.Internal.Data.Stream.Chunked as AS
136import qualified Streamly.Internal.Data.MutArray.Type as MArray
137import qualified Streamly.Internal.Data.Refold.Type as Refold
138import qualified Streamly.Internal.Data.Fold.Type as FL(refoldMany)
139import qualified Streamly.Internal.Data.Stream as S
140import qualified Streamly.Internal.Data.Stream.StreamD.Type as D
141 (Stream(..), Step(..))
142import qualified Streamly.Internal.Data.Unfold as UF
143import qualified Streamly.Internal.Data.Stream.StreamK.Type as K (mkStream)
146-- >>> import qualified Streamly.Data.Array as Array
147-- >>> import qualified Streamly.Data.Fold as Fold
148-- >>> import qualified Streamly.Data.Unfold as Unfold
149-- >>> import qualified Streamly.Data.Stream as Stream
151-- >>> import qualified Streamly.Internal.Data.Array.Type as Array (writeNUnsafe)
152-- >>> import qualified Streamly.Internal.Data.Stream as Stream
153-- >>> import qualified Streamly.Internal.Data.Unfold as Unfold (first)
154-- >>> import qualified Streamly.Internal.FileSystem.Handle as Handle
155-- >>> import qualified Streamly.Internal.System.IO as IO (defaultChunkSize)
157-------------------------------------------------------------------------------
159-------------------------------------------------------------------------------
161-- The following references may be useful to build an understanding about the
164-- http://www.linux-mag.com/id/308/ for blocking/non-blocking IO on linux.
165-- https://lwn.net/Articles/612483/ Non-blocking buffered file read operations
166-- https://en.wikipedia.org/wiki/C_file_input/output for C APIs.
167-- https://docs.oracle.com/javase/tutorial/essential/io/file.html for Java API.
168-- https://www.w3.org/TR/FileAPI/ for http file API.
170-------------------------------------------------------------------------------
172-------------------------------------------------------------------------------
174-- | Read a 'ByteArray' consisting of one or more bytes from a file handle. If
175-- no data is available on the handle it blocks until at least one byte becomes
176-- available. If any data is available then it immediately returns that data
177-- without blocking. As a result of this behavior, it may read less than or
178-- equal to the size requested.
180{-# INLINABLE getChunk #-}
181getChunk :: MonadIO m => Int -> Handle -> m (Array Word8)
182getChunk size h = liftIO $ do
183 arr <- MArray.pinnedNewBytes 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-- | @readChunksWith 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-- >>> readChunksWith size h = Stream.unfold Handle.chunkReaderWith (size, h)
229{-# INLINE_NORMAL readChunksWith #-}
230readChunksWith :: MonadIO m => Int -> Handle -> Stream m (Array Word8)
231readChunksWith size h = D.Stream step ()
233 {-# INLINE_LATE step #-}
235 arr <- getChunk size h
237 case byteLength arr of
241-- | Unfold the tuple @(bufsize, handle)@ into a stream of 'Word8' arrays.
242-- Read requests to the IO device are performed using a buffer of size
243-- @bufsize@. The size of an array in the resulting stream is always less than
244-- or equal to @bufsize@.
246{-# INLINE_NORMAL chunkReaderWith #-}
247chunkReaderWith :: MonadIO m => Unfold m (Int, Handle) (Array Word8)
249 UF.lmap (uncurry getChunk) UF.repeatM
250 & UF.takeWhile ((/= 0) . byteLength)
252-- | Same as 'chunkReaderWith'
254{-# DEPRECATED readChunksWithBufferOf "Please use chunkReaderWith instead." #-}
255{-# INLINE_NORMAL readChunksWithBufferOf #-}
256readChunksWithBufferOf :: MonadIO m => Unfold m (Int, Handle) (Array Word8)
257readChunksWithBufferOf = chunkReaderWith
259-- There are two ways to implement this.
261-- 1. Idiomatic: use a scan on the output of readChunksWith to total
262-- the array lengths and trim the last array to correct size.
263-- 2. Simply implement it from scratch like readChunksWith.
265-- XXX Change this to readChunksWithFromTo (bufferSize, from, to, h)?
267-- | The input to the unfold is @(from, to, bufferSize, handle)@. It starts
268-- reading from the offset `from` in the file and reads up to the offset `to`.
270{-# INLINE_NORMAL chunkReaderFromToWith #-}
271chunkReaderFromToWith :: MonadIO m =>
272 Unfold m (Int, Int, Int, Handle) (Array Word8)
273chunkReaderFromToWith = Unfold step inject
277 inject (from, to, bufSize, h) = do
278 liftIO $ hSeek h AbsoluteSeek $ fromIntegral from
279 -- XXX Use a strict Tuple?
280 return (to - from + 1, bufSize, h)
282 {-# INLINE_LATE step #-}
283 step (remaining, bufSize, h) =
287 arr <- getChunk (min bufSize remaining) h
289 case byteLength arr of
292 assert (len <= remaining)
293 $ D.Yield arr (remaining - len, bufSize, h)
295-- | @getChunks handle@ reads a stream of arrays from the specified file
296-- handle. The maximum size of a single array is limited to
297-- @defaultChunkSize@. The actual size read may be less than or equal to
298-- @defaultChunkSize@.
300-- >>> readChunks = Handle.readChunksWith IO.defaultChunkSize
303{-# INLINE readChunks #-}
304readChunks :: MonadIO m => Handle -> Stream m (Array Word8)
305readChunks = readChunksWith defaultChunkSize
307-- | Unfolds a handle 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'.
313-- >>> chunkReader = Unfold.first IO.defaultChunkSize Handle.chunkReaderWith
315{-# INLINE chunkReader #-}
316chunkReader :: MonadIO m => Unfold m Handle (Array Word8)
317chunkReader = UF.first defaultChunkSize chunkReaderWith
319-------------------------------------------------------------------------------
320-- Read File to Stream
321-------------------------------------------------------------------------------
323-- TODO for concurrent streams implement readahead IO. We can send multiple
324-- read requests at the same time. For serial case we can use async IO. We can
325-- also control the read throughput in mbps or IOPS.
327-- | Unfolds the tuple @(bufsize, handle)@ into a byte stream, read requests
328-- to the IO device are performed using buffers of @bufsize@.
330-- >>> readerWith = Unfold.many Array.reader Handle.chunkReaderWith
332{-# INLINE readerWith #-}
333readerWith :: MonadIO m => Unfold m (Int, Handle) Word8
334readerWith = UF.many A.reader chunkReaderWith
336-- | Same as 'readerWith'
338{-# DEPRECATED readWithBufferOf "Please use 'readerWith' instead." #-}
339{-# INLINE readWithBufferOf #-}
340readWithBufferOf :: MonadIO m => Unfold m (Int, Handle) Word8
341readWithBufferOf = readerWith
343{-# INLINE concatChunks #-}
344concatChunks :: (Monad m, Unbox a) => Stream m (Array a) -> Stream m a
345concatChunks = S.unfoldMany A.reader
347-- | @readWith bufsize handle@ reads a byte stream from a file
348-- handle, reads are performed in chunks of up to @bufsize@.
350-- >>> readWith size h = Stream.unfoldMany Array.reader $ Handle.readChunksWith size h
353{-# INLINE readWith #-}
354readWith :: MonadIO m => Int -> Handle -> Stream m Word8
355readWith size h = concatChunks $ readChunksWith size h
357-- | Unfolds a file handle into a byte stream. IO requests to the device are
358-- performed in sizes of
359-- 'Streamly.Internal.Data.Array.Type.defaultChunkSize'.
361-- >>> reader = Unfold.many Array.reader chunkReader
364reader :: MonadIO m => Unfold m Handle Word8
365reader = UF.many A.reader chunkReader
367-- | Generate a byte stream from a file 'Handle'.
369-- >>> read h = Stream.unfoldMany Array.reader $ Handle.readChunks h
373read :: MonadIO m => Handle -> Stream m Word8
374read = concatChunks . readChunks
376-------------------------------------------------------------------------------
378-------------------------------------------------------------------------------
380-------------------------------------------------------------------------------
382-------------------------------------------------------------------------------
384-- | Write an 'Array' to a file handle.
386{-# INLINABLE putChunk #-}
387putChunk :: MonadIO m => Handle -> Array a -> m ()
388putChunk _ arr | byteLength arr == 0 = return ()
389putChunk h arr = A.asPtrUnsafe arr $ \ptr ->
390 liftIO $ hPutBuf h ptr aLen
394 -- XXX We should have the length passed by asPtrUnsafe itself.
395 aLen = A.byteLength arr
397-------------------------------------------------------------------------------
398-- Stream of Arrays IO
399-------------------------------------------------------------------------------
401-------------------------------------------------------------------------------
403-------------------------------------------------------------------------------
405-- XXX use an unfold to fromObjects or fromUnfold so that we can put any object
406-- | Write a stream of arrays to a handle.
408-- >>> putChunks h = Stream.fold (Fold.drainBy (Handle.putChunk h))
410{-# INLINE putChunks #-}
411putChunks :: MonadIO m => Handle -> Stream m (Array a) -> m ()
412putChunks h = S.fold (FL.drainMapM (putChunk h))
414-- XXX AS.compact can be written idiomatically in terms of foldMany, just like
415-- AS.concat is written in terms of foldMany. Once that is done we can write
416-- idiomatic def in the docs.
418-- | @putChunksWith bufsize handle stream@ writes a stream of arrays
419-- to @handle@ after coalescing the adjacent arrays in chunks of @bufsize@.
420-- The chunk size is only a maximum and the actual writes could be smaller as
421-- we do not split the arrays to fit exactly to the specified size.
423{-# INLINE putChunksWith #-}
424putChunksWith :: (MonadIO m, Unbox a)
425 => Int -> Handle -> Stream m (Array a) -> m ()
426putChunksWith n h xs = putChunks h $ AS.compact n xs
428-- > putBytesWith n h m = Handle.putChunks h $ A.pinnedChunksOf n m
430-- | @putBytesWith bufsize handle stream@ writes @stream@ to @handle@
431-- in chunks of @bufsize@. A write is performed to the IO device as soon as we
432-- collect the required input size.
434{-# INLINE putBytesWith #-}
435putBytesWith :: MonadIO m => Int -> Handle -> Stream m Word8 -> m ()
436putBytesWith n h m = putChunks h $ A.pinnedChunksOf n m
438-- | Write a byte stream to a file handle. Accumulates the input in chunks of
439-- up to 'Streamly.Internal.Data.Array.Type.defaultChunkSize' before writing.
441-- NOTE: This may perform better than the 'write' fold, you can try this if you
442-- need some extra perf boost.
444-- >>> putBytes = Handle.putBytesWith IO.defaultChunkSize
446{-# INLINE putBytes #-}
447putBytes :: MonadIO m => Handle -> Stream m Word8 -> m ()
448putBytes = putBytesWith defaultChunkSize
450-- | Write a stream of arrays to a handle. Each array in the stream is written
451-- to the device as a separate IO request.
453-- writeChunks h = Fold.drainBy (Handle.putChunk h)
455{-# INLINE writeChunks #-}
456writeChunks :: MonadIO m => Handle -> Fold m (Array a) ()
457writeChunks h = FL.drainMapM (putChunk h)
459-- | Like writeChunks but uses the experimental 'Refold' API.
462{-# INLINE chunkWriter #-}
463chunkWriter :: MonadIO m => Refold m Handle (Array a) ()
464chunkWriter = Refold.drainBy putChunk
466-- XXX lpackArraysChunksOf should be written idiomatically
468-- | @writeChunksWith bufsize handle@ writes a stream of arrays
469-- to @handle@ after coalescing the adjacent arrays in chunks of @bufsize@.
470-- We never split an array, if a single array is bigger than the specified size
471-- it emitted as it is. Multiple arrays are coalesed as long as the total size
472-- remains below the specified size.
474{-# INLINE writeChunksWith #-}
475writeChunksWith :: (MonadIO m, Unbox a)
476 => Int -> Handle -> Fold m (Array a) ()
477writeChunksWith n h = lpackArraysChunksOf n (writeChunks h)
479-- | Same as 'writeChunksWith'
481{-# DEPRECATED writeChunksWithBufferOf "Please use writeChunksWith instead." #-}
482{-# INLINE writeChunksWithBufferOf #-}
483writeChunksWithBufferOf :: (MonadIO m, Unbox a)
484 => Int -> Handle -> Fold m (Array a) ()
485writeChunksWithBufferOf = writeChunksWith
487-- GHC buffer size dEFAULT_FD_BUFFER_SIZE=8192 bytes.
490-- Note that if you use a chunk size less than 8K (GHC's default buffer
491-- size) then you are advised to use 'NOBuffering' mode on the 'Handle' in case you
492-- do not want buffering to occur at GHC level as well. Same thing applies to
495-- XXX Maybe we should have a Fold.chunksOf like we have Stream.chunksOf
497-- | @writeWith reqSize handle@ writes the input stream to @handle@.
498-- Bytes in the input stream are collected into a buffer until we have a chunk
499-- of @reqSize@ and then written to the IO device.
501-- >>> writeWith n h = Fold.groupsOf n (Array.writeNUnsafe n) (Handle.writeChunks h)
503{-# INLINE writeWith #-}
504writeWith :: MonadIO m => Int -> Handle -> Fold m Word8 ()
505writeWith n h = FL.groupsOf n (pinnedWriteNUnsafe n) (writeChunks h)
507-- | Same as 'writeWith'
509{-# DEPRECATED writeWithBufferOf "Please use writeWith instead." #-}
510{-# INLINE writeWithBufferOf #-}
511writeWithBufferOf :: MonadIO m => Int -> Handle -> Fold m Word8 ()
512writeWithBufferOf = writeWith
514-- | Write a stream of 'Maybe' values. Keep buffering the just values in an
515-- array until a 'Nothing' is encountered or the buffer size exceeds the
516-- specified limit, at that point flush the buffer to the handle.
519{-# INLINE writeMaybesWith #-}
520writeMaybesWith :: (MonadIO m )
521 => Int -> Handle -> Fold m (Maybe Word8) ()
523 let writeNJusts = FL.lmap fromJust $ A.pinnedWriteN n
524 writeOnNothing = FL.takeEndBy_ isNothing writeNJusts
525 in FL.many writeOnNothing (writeChunks h)
527-- | Like 'writeWith' but uses the experimental 'Refold' API.
530{-# INLINE writerWith #-}
531writerWith :: MonadIO m => Int -> Refold m Handle Word8 ()
533 FL.refoldMany (FL.take n $ pinnedWriteNUnsafe n) chunkWriter
535-- | Write a byte stream to a file handle. Accumulates the input in chunks of
536-- up to 'Streamly.Internal.Data.Array.Type.defaultChunkSize' before writing
539-- >>> write = Handle.writeWith IO.defaultChunkSize
542write :: MonadIO m => Handle -> Fold m Word8 ()
543write = writeWith defaultChunkSize
545-- | Like 'write' but uses the experimental 'Refold' API.
549writer :: MonadIO m => Refold m Handle Word8 ()
550writer = writerWith defaultChunkSize
552-- XXX mmap a file into an array. This could be useful for in-place operations
553-- on a file. For example, we can quicksort the contents of a file by mmapping
556-------------------------------------------------------------------------------
557-- IO with encoding/decoding Unicode characters
558-------------------------------------------------------------------------------
562-- > readUtf8 = decodeUtf8 . read
564-- Read a UTF8 encoded stream of unicode characters from a file handle.
566{-# INLINE readUtf8 #-}
567readUtf8 :: MonadIO m => Handle -> Stream m Char
568readUtf8 = decodeUtf8 . read
571-- > writeUtf8 h s = write h $ encodeUtf8 s
573-- Encode a stream of unicode characters to UTF8 and write it to the given file
574-- handle. Default block buffering applies to the writes.
576{-# INLINE writeUtf8 #-}
577writeUtf8 :: MonadIO m => Handle -> Stream m Char -> m ()
578writeUtf8 h s = write h $ encodeUtf8 s
580-- | Write a stream of unicode characters after encoding to UTF-8 in chunks
581-- separated by a linefeed character @'\n'@. If the size of the buffer exceeds
582-- @defaultChunkSize@ and a linefeed is not yet found, the buffer is written
583-- anyway. This is similar to writing to a 'Handle' with the 'LineBuffering'
586{-# INLINE writeUtf8ByLines #-}
587writeUtf8ByLines :: MonadIO m => Handle -> Stream m Char -> m ()
588writeUtf8ByLines = undefined
590-- | Read UTF-8 lines from a file handle and apply the specified fold to each
591-- line. This is similar to reading a 'Handle' with the 'LineBuffering' option.
593{-# INLINE readLines #-}
594readLines :: MonadIO m => Handle -> Fold m Char b -> Stream m b
595readLines h f = foldLines (readUtf8 h) f
597-------------------------------------------------------------------------------
598-- Framing on a sequence
599-------------------------------------------------------------------------------
601-- | Read a stream from a file handle and split it into frames delimited by
602-- the specified sequence of elements. The supplied fold is applied on each
605{-# INLINE readFrames #-}
606readFrames :: (MonadIO m, Unboxed a)
607 => Array a -> Handle -> Fold m a b -> Stream m b
608readFrames = undefined -- foldFrames . read
610-- | Write a stream to the given file handle buffering up to frames separated
611-- by the given sequence or up to a maximum of @defaultChunkSize@.
613{-# INLINE writeByFrames #-}
614writeByFrames :: (MonadIO m, Unboxed a)
615 => Array a -> Handle -> Stream m a -> m ()
616writeByFrames = undefined
618-------------------------------------------------------------------------------
620-------------------------------------------------------------------------------
622-- | Write collecting the input in sessions of n seconds or if chunkSize
624{-# INLINE writeByChunksOrSessionsOf #-}
625writeByChunksOrSessionsOf :: MonadIO m
626 => Int -> Double -> Handle -> Stream m Word8 -> m ()
627writeByChunksOrSessionsOf chunkSize sessionSize h m = undefined
629-- | Write collecting the input in sessions of n seconds or if defaultChunkSize
631{-# INLINE writeBySessionsOf #-}
632writeBySessionsOf :: MonadIO m => Double -> Handle -> Stream m Word8 -> m ()
633writeBySessionsOf n = writeByChunksOrSessionsOf defaultChunkSize n
635-------------------------------------------------------------------------------
636-- Random Access IO (Seek)
637-------------------------------------------------------------------------------
639-- XXX handles could be shared, so we may not want to use the handle state at
640-- all for these APIs. we can use pread and pwrite instead. On windows we will
641-- need to use readFile/writeFile with an offset argument.
643-------------------------------------------------------------------------------
645-- | Read the element at the given index treating the file as an array.
647{-# INLINE readIndex #-}
648readIndex :: Unboxed a => Handle -> Int -> Maybe a
649readIndex arr i = undefined
651-- NOTE: To represent a range to read we have chosen (start, size) instead of
652-- (start, end). This helps in removing the ambiguity of whether "end" is
653-- included in the range or not.
655-- We could avoid specifying the range to be read and instead use "take size"
656-- on the stream, but it may end up reading more and then consume it partially.
658-- | @readSliceWith chunkSize handle pos len@ reads up to @len@ bytes
659-- from @handle@ starting at the offset @pos@ from the beginning of the file.
661-- Reads are performed in chunks of size @chunkSize@. For block devices, to
662-- avoid reading partial blocks @chunkSize@ must align with the block size of
663-- the underlying device. If the underlying block size is unknown, it is a good
664-- idea to keep it a multiple 4KiB. This API ensures that the start of each
665-- chunk is aligned with @chunkSize@ from second chunk onwards.
667{-# INLINE readSliceWith #-}
668readSliceWith :: (MonadIO m, Unboxed a)
669 => Int -> Handle -> Int -> Int -> Stream m a
670readSliceWith chunkSize h pos len = undefined
672-- | @readSlice h i count@ streams a slice from the file handle @h@ starting
673-- at index @i@ and reading up to @count@ elements in the forward direction
674-- ending at the index @i + count - 1@.
676{-# INLINE readSlice #-}
677readSlice :: (MonadIO m, Unboxed a)
678 => Handle -> Int -> Int -> Stream m a
679readSlice = readSliceWith A.defaultChunkSize
681-- | @readSliceRev h i count@ streams a slice from the file handle @h@ starting
682-- at index @i@ and reading up to @count@ elements in the reverse direction
683-- ending at the index @i - count + 1@.
685{-# INLINE readSliceRev #-}
686readSliceRev :: (MonadIO m, Unboxed a)
687 => Handle -> Int -> Int -> Stream m a
688readSliceRev h i count = undefined
690-- | Write the given element at the given index in the file.
692{-# INLINE writeIndex #-}
693writeIndex :: (MonadIO m, Unboxed a) => Handle -> Int -> a -> m ()
694writeIndex h i a = undefined
696-- | @writeSlice h i count stream@ writes a stream to the file handle @h@
697-- starting at index @i@ and writing up to @count@ elements in the forward
698-- direction ending at the index @i + count - 1@.
700{-# INLINE writeSlice #-}
701writeSlice :: (Monad m, Unboxed a)
702 => Handle -> Int -> Int -> Stream m a -> m ()
703writeSlice h i len s = undefined
705-- | @writeSliceRev h i count stream@ writes a stream to the file handle @h@
706-- starting at index @i@ and writing up to @count@ elements in the reverse
707-- direction ending at the index @i - count + 1@.
709{-# INLINE writeSliceRev #-}
710writeSliceRev :: (Monad m, Unboxed a)
711 => Handle -> Int -> Int -> Stream m a -> m ()
712writeSliceRev 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