6-- Module : Streamly.Internal.FileSystem.Handle
7-- Copyright : (c) 2018 Composewell Technologies
10-- Maintainer : streamly@composewell.com
11-- Stability : experimental
14-- The fundamental singleton IO APIs are 'getChunk' and 'putChunk' and the
15-- fundamental stream IO APIs built on top of those are
16-- 'readChunksWith' and 'writeChunks'. Rest of this module is just
17-- combinatorial programming using these.
19-- We can achieve line buffering by folding lines in the input stream into a
20-- stream of arrays using Stream.splitOn or Fold.takeEndBy_ and similar
21-- operations. One can wrap the input stream in 'Maybe' type and then use
22-- 'writeMaybesWith' to achieve user controlled buffering.
24-- TODO: Need a separate module for pread/pwrite based reading writing for
25-- seekable devices. Stateless read/write can be helpful in multithreaded
28module Streamly.Internal.FileSystem.Handle
31 -- | To execute the code examples provided in this module in ghci, please
32 -- run the following commands first.
43 , readWith -- readConcatChunksOf
44 , readChunksWith -- readChunksOf
62 , writeWith -- writeChunksOf
64 , writeChunksWith -- writeCompactChunksOf
65 , writeMaybesWith -- writeCompactJustsOf
79 -- * Random Access (Seek)
80 -- | Unlike the streaming APIs listed above, these APIs apply to devices or
81 -- files that have random access or seek capability. This type of devices
82 -- include disks, files, memory devices and exclude terminals, pipes,
85 -- We can also generate the request pattern using a funciton.
88 -- , readFrom -- read from a given position to the end of file
89 -- , readFromRev -- read from a given position the beginning of file
90 -- , readTo -- read from beginning up to the given position
91 -- , readToRev -- read from end to the given position in file
97 , chunkReaderFromToWith
98 -- , readChunksFromThenToWith
101 -- , writeFrom -- start writing at the given position
103 -- , writeTo -- write from beginning up to the given position
109 -- , writeChunksFromTo
110 -- , writeChunksFromToWith
111 -- , writeChunksFromThenToWith
114 , readChunksWithBufferOf
116 , writeChunksWithBufferOf
121import Control.Exception (assert)
122import Control.Monad.IO.Class (MonadIO(..))
123import Data.Function ((&))
124import Data.Maybe (isNothing, fromJust)
125import Data.Word (Word8)
126import Streamly.Internal.Data.Unbox (Unbox)
127import System.IO (Handle, SeekMode(..), hGetBufSome, hPutBuf, hSeek)
128import Prelude hiding (read)
130import Streamly.Internal.Data.Fold (Fold)
131import Streamly.Internal.Data.Refold.Type (Refold(..))
132import Streamly.Internal.Data.Unfold.Type (Unfold(..))
133import Streamly.Internal.Data.Array.Type
134 (Array(..), unsafeFreezeWithShrink, byteLength)
135import Streamly.Internal.Data.Stream.Type (Stream)
136-- import Streamly.String (encodeUtf8, decodeUtf8, foldLines)
137import Streamly.Internal.System.IO (defaultChunkSize)
139import qualified Streamly.Data.Fold as FL
140import qualified Streamly.Internal.Data.Array as A
141import qualified Streamly.Internal.Data.MutArray.Type as MArray
142import qualified Streamly.Internal.Data.Refold.Type as Refold
143import qualified Streamly.Internal.Data.Fold.Type as FL(refoldMany)
144import qualified Streamly.Internal.Data.Stream as S
145import qualified Streamly.Internal.Data.Stream as D
146 (Stream(..), Step(..))
147import qualified Streamly.Internal.Data.Unfold as UF
148import qualified Streamly.Internal.Data.StreamK.Type as K (mkStream)
150#include "DocTestFileSystemHandle.hs"
152-------------------------------------------------------------------------------
154-------------------------------------------------------------------------------
156-- The following references may be useful to build an understanding about the
159-- http://www.linux-mag.com/id/308/ for blocking/non-blocking IO on linux.
160-- https://lwn.net/Articles/612483/ Non-blocking buffered file read operations
161-- https://en.wikipedia.org/wiki/C_file_input/output for C APIs.
162-- https://docs.oracle.com/javase/tutorial/essential/io/file.html for Java API.
163-- https://www.w3.org/TR/FileAPI/ for http file API.
165-------------------------------------------------------------------------------
167-------------------------------------------------------------------------------
169-- XXX add an API that compacts the arrays to an exact size.
171-- | Read a 'ByteArray' consisting of one or more bytes from a file handle. If
172-- no data is available on the handle it blocks until at least one byte becomes
173-- available. If any data is available then it immediately returns that data
174-- without blocking. As a result of this behavior, it may read less than or
175-- equal to the size requested.
177{-# INLINABLE getChunk #-}
178getChunk :: MonadIO m => Int -> Handle -> m (Array Word8)
179getChunk size h = liftIO $ do
180 arr :: MArray.MutArray Word8 <- MArray.pinnedEmptyOf size
181 -- ptr <- mallocPlainForeignPtrAlignedBytes size (alignment (undefined :: Word8))
182 MArray.unsafePinnedAsPtr arr $ \p -> do
183 n <- hGetBufSome h p size
184 -- XXX shrink only if the diff is significant
186 unsafeFreezeWithShrink $
187 arr { MArray.arrEnd = n, MArray.arrBound = size }
189-- This could be useful in implementing the "reverse" read APIs or if you want
190-- to read arrays of exact size instead of compacting them later. Compacting
191-- later requires more copying.
193-- | Read a 'ByteArray' consisting of exactly the specified number of bytes
194-- from a file handle.
197{-# INLINABLE getChunkOf #-}
198getChunkOf :: Int -> Handle -> IO (Array Word8)
199getChunkOf = undefined
201-------------------------------------------------------------------------------
202-- Stream of Arrays IO
203-------------------------------------------------------------------------------
205-- | @getChunksWith size h@ reads a stream of arrays from file handle @h@.
206-- The maximum size of a single array is specified by @size@. The actual size
207-- read may be less than or equal to @size@.
209{-# INLINE _getChunksWith #-}
210_getChunksWith :: MonadIO m => Int -> Handle -> Stream m (Array Word8)
211_getChunksWith size h = S.fromStreamK go
213 -- XXX use cons/nil instead
214 go = K.mkStream $ \_ yld _ stp -> do
215 arr <- getChunk size h
216 if byteLength arr == 0
220-- | @readChunksWith size handle@ reads a stream of arrays from the file
221-- handle @handle@. The maximum size of a single array is limited to @size@.
222-- The actual size read may be less than or equal to @size@.
224-- >>> readChunksWith size h = Stream.unfold Handle.chunkReaderWith (size, h)
226{-# INLINE_NORMAL readChunksWith #-}
227readChunksWith :: MonadIO m => Int -> Handle -> Stream m (Array Word8)
228readChunksWith size h = D.Stream step ()
230 {-# INLINE_LATE step #-}
232 arr <- getChunk size h
234 case byteLength arr of
238-- | Unfold the tuple @(bufsize, handle)@ into a stream of 'Word8' arrays.
239-- Read requests to the IO device are performed using a buffer of size
240-- @bufsize@. The size of an array in the resulting stream is always less than
241-- or equal to @bufsize@.
243{-# INLINE_NORMAL chunkReaderWith #-}
244chunkReaderWith :: MonadIO m => Unfold m (Int, Handle) (Array Word8)
246 UF.lmap (uncurry getChunk) UF.repeatM
247 & UF.takeWhile ((/= 0) . byteLength)
249-- | Same as 'chunkReaderWith'
251{-# DEPRECATED readChunksWithBufferOf "Please use chunkReaderWith instead." #-}
252{-# INLINE_NORMAL readChunksWithBufferOf #-}
253readChunksWithBufferOf :: MonadIO m => Unfold m (Int, Handle) (Array Word8)
254readChunksWithBufferOf = chunkReaderWith
256-- There are two ways to implement this.
258-- 1. Idiomatic: use a scan on the output of readChunksWith to total
259-- the array lengths and trim the last array to correct size.
260-- 2. Simply implement it from scratch like readChunksWith.
262-- XXX Change this to readChunksWithFromTo (bufferSize, from, to, h)?
264-- | The input to the unfold is @(from, to, bufferSize, handle)@. It starts
265-- reading from the offset `from` in the file and reads up to the offset `to`.
267{-# INLINE_NORMAL chunkReaderFromToWith #-}
268chunkReaderFromToWith :: MonadIO m =>
269 Unfold m (Int, Int, Int, Handle) (Array Word8)
270chunkReaderFromToWith = Unfold step inject
274 inject (from, to, bufSize, h) = do
275 liftIO $ hSeek h AbsoluteSeek $ fromIntegral from
276 -- XXX Use a strict Tuple?
277 return (to - from + 1, bufSize, h)
279 {-# INLINE_LATE step #-}
280 step (remaining, bufSize, h) =
284 arr <- getChunk (min bufSize remaining) h
286 case byteLength arr of
289 assert (len <= remaining)
290 $ D.Yield arr (remaining - len, bufSize, h)
292-- | @getChunks handle@ reads a stream of arrays from the specified file
293-- handle. The maximum size of a single array is limited to
294-- @defaultChunkSize@. The actual size read may be less than or equal to
295-- @defaultChunkSize@.
297-- >>> readChunks = Handle.readChunksWith IO.defaultChunkSize
300{-# INLINE readChunks #-}
301readChunks :: MonadIO m => Handle -> Stream m (Array Word8)
302readChunks = readChunksWith defaultChunkSize
304-- | Unfolds a handle into a stream of 'Word8' arrays. Requests to the IO
305-- device are performed using a buffer of size
306-- 'Streamly.Internal.Data.Array.Type.defaultChunkSize'. The
307-- size of arrays in the resulting stream are therefore less than or equal to
308-- 'Streamly.Internal.Data.Array.Type.defaultChunkSize'.
310-- >>> chunkReader = Unfold.first IO.defaultChunkSize Handle.chunkReaderWith
312{-# INLINE chunkReader #-}
313chunkReader :: MonadIO m => Unfold m Handle (Array Word8)
314chunkReader = UF.first defaultChunkSize chunkReaderWith
316-------------------------------------------------------------------------------
317-- Read File to Stream
318-------------------------------------------------------------------------------
320-- TODO for concurrent streams implement readahead IO. We can send multiple
321-- read requests at the same time. For serial case we can use async IO. We can
322-- also control the read throughput in mbps or IOPS.
324-- | Unfolds the tuple @(bufsize, handle)@ into a byte stream, read requests
325-- to the IO device are performed using buffers of @bufsize@.
327-- >>> readerWith = Unfold.many Array.reader Handle.chunkReaderWith
329{-# INLINE readerWith #-}
330readerWith :: MonadIO m => Unfold m (Int, Handle) Word8
331readerWith = UF.many A.reader chunkReaderWith
333-- | Same as 'readerWith'
335{-# DEPRECATED readWithBufferOf "Please use 'readerWith' instead." #-}
336{-# INLINE readWithBufferOf #-}
337readWithBufferOf :: MonadIO m => Unfold m (Int, Handle) Word8
338readWithBufferOf = readerWith
340-- | @readWith bufsize handle@ reads a byte stream from a file
341-- handle, reads are performed in chunks of up to @bufsize@.
343-- >>> readWith size h = Stream.unfoldMany Array.reader $ Handle.readChunksWith size h
346{-# INLINE readWith #-}
347readWith :: MonadIO m => Int -> Handle -> Stream m Word8
348readWith size h = A.concat $ readChunksWith size h
350-- | Unfolds a file handle into a byte stream. IO requests to the device are
351-- performed in sizes of
352-- 'Streamly.Internal.Data.Array.Type.defaultChunkSize'.
354-- >>> reader = Unfold.many Array.reader Handle.chunkReader
357reader :: MonadIO m => Unfold m Handle Word8
358reader = UF.many A.reader chunkReader
360-- | Generate a byte stream from a file 'Handle'.
362-- >>> read h = Stream.unfoldMany Array.reader $ Handle.readChunks h
366read :: MonadIO m => Handle -> Stream m Word8
367read = A.concat . readChunks
369-------------------------------------------------------------------------------
371-------------------------------------------------------------------------------
373-------------------------------------------------------------------------------
375-------------------------------------------------------------------------------
377-- | Write an 'Array' to a file handle.
379{-# INLINABLE putChunk #-}
380putChunk :: MonadIO m => Handle -> Array a -> m ()
381putChunk _ arr | byteLength arr == 0 = return ()
382putChunk h arr = A.unsafePinnedAsPtr arr $ \ptr ->
383 liftIO $ hPutBuf h ptr aLen
387 -- XXX We should have the length passed by unsafePinnedAsPtr itself.
388 aLen = A.byteLength arr
390-------------------------------------------------------------------------------
391-- Stream of Arrays IO
392-------------------------------------------------------------------------------
394-------------------------------------------------------------------------------
396-------------------------------------------------------------------------------
398-- XXX use an unfold to fromObjects or fromUnfold so that we can put any object
399-- | Write a stream of arrays to a handle.
401-- >>> putChunks h = Stream.fold (Fold.drainBy (Handle.putChunk h))
403{-# INLINE putChunks #-}
404putChunks :: MonadIO m => Handle -> Stream m (Array a) -> m ()
405putChunks h = S.fold (FL.drainMapM (putChunk h))
407-- XXX AS.compact can be written idiomatically in terms of foldMany, just like
408-- AS.concat is written in terms of foldMany. Once that is done we can write
409-- idiomatic def in the docs.
411-- | @putChunksWith bufsize handle stream@ writes a stream of arrays
412-- to @handle@ after coalescing the adjacent arrays in chunks of @bufsize@.
413-- The chunk size is only a maximum and the actual writes could be smaller as
414-- we do not split the arrays to fit exactly to the specified size.
416{-# INLINE putChunksWith #-}
417putChunksWith :: (MonadIO m, Unbox a)
418 => Int -> Handle -> Stream m (Array a) -> m ()
419putChunksWith n h xs = putChunks h $ A.compactLE n xs
421-- > putBytesWith n h m = Handle.putChunks h $ A.pinnedChunksOf n m
423-- | @putBytesWith bufsize handle stream@ writes @stream@ to @handle@
424-- in chunks of @bufsize@. A write is performed to the IO device as soon as we
425-- collect the required input size.
427{-# INLINE putBytesWith #-}
428putBytesWith :: MonadIO m => Int -> Handle -> Stream m Word8 -> m ()
429putBytesWith n h m = putChunks h $ A.pinnedChunksOf n m
431-- | Write a byte stream to a file handle. Accumulates the input in chunks of
432-- up to 'Streamly.Internal.Data.Array.Type.defaultChunkSize' before writing.
434-- NOTE: This may perform better than the 'write' fold, you can try this if you
435-- need some extra perf boost.
437-- >>> putBytes = Handle.putBytesWith IO.defaultChunkSize
439{-# INLINE putBytes #-}
440putBytes :: MonadIO m => Handle -> Stream m Word8 -> m ()
441putBytes = putBytesWith defaultChunkSize
443-- | Write a stream of arrays to a handle. Each array in the stream is written
444-- to the device as a separate IO request.
446-- writeChunks h = Fold.drainBy (Handle.putChunk h)
448{-# INLINE writeChunks #-}
449writeChunks :: MonadIO m => Handle -> Fold m (Array a) ()
450writeChunks h = FL.drainMapM (putChunk h)
452-- | Like writeChunks but uses the experimental 'Refold' API.
455{-# INLINE chunkWriter #-}
456chunkWriter :: MonadIO m => Refold m Handle (Array a) ()
457chunkWriter = Refold.drainBy putChunk
459-- | @writeChunksWith bufsize handle@ writes a stream of arrays
460-- to @handle@ after coalescing the adjacent arrays in chunks of @bufsize@.
461-- We never split an array, if a single array is bigger than the specified size
462-- it emitted as it is. Multiple arrays are coalesed as long as the total size
463-- remains below the specified size.
465{-# INLINE writeChunksWith #-}
466writeChunksWith :: (MonadIO m, Unbox a)
467 => Int -> Handle -> Fold m (Array a) ()
468writeChunksWith n h = A.lCompactGE n (writeChunks h)
470-- | Same as 'writeChunksWith'
472{-# DEPRECATED writeChunksWithBufferOf "Please use writeChunksWith instead." #-}
473{-# INLINE writeChunksWithBufferOf #-}
474writeChunksWithBufferOf :: (MonadIO m, Unbox a)
475 => Int -> Handle -> Fold m (Array a) ()
476writeChunksWithBufferOf = writeChunksWith
478-- GHC buffer size dEFAULT_FD_BUFFER_SIZE=8192 bytes.
481-- Note that if you use a chunk size less than 8K (GHC's default buffer
482-- size) then you are advised to use 'NOBuffering' mode on the 'Handle' in case you
483-- do not want buffering to occur at GHC level as well. Same thing applies to
486-- XXX Maybe we should have a Fold.chunksOf like we have Stream.chunksOf
488-- | @writeWith reqSize handle@ writes the input stream to @handle@.
489-- Bytes in the input stream are collected into a buffer until we have a chunk
490-- of @reqSize@ and then written to the IO device.
492-- >>> writeWith n h = Fold.groupsOf n (Array.unsafeCreateOf n) (Handle.writeChunks h)
494{-# INLINE writeWith #-}
495writeWith :: MonadIO m => Int -> Handle -> Fold m Word8 ()
496writeWith n h = FL.groupsOf n (A.unsafePinnedCreateOf n) (writeChunks h)
498-- | Same as 'writeWith'
500{-# DEPRECATED writeWithBufferOf "Please use writeWith instead." #-}
501{-# INLINE writeWithBufferOf #-}
502writeWithBufferOf :: MonadIO m => Int -> Handle -> Fold m Word8 ()
503writeWithBufferOf = writeWith
505-- | Write a stream of 'Maybe' values. Keep buffering the just values in an
506-- array until a 'Nothing' is encountered or the buffer size exceeds the
507-- specified limit, at that point flush the buffer to the handle.
510{-# INLINE writeMaybesWith #-}
511writeMaybesWith :: (MonadIO m )
512 => Int -> Handle -> Fold m (Maybe Word8) ()
514 let writeNJusts = FL.lmap fromJust $ A.pinnedCreateOf n
515 writeOnNothing = FL.takeEndBy_ isNothing writeNJusts
516 in FL.many writeOnNothing (writeChunks h)
518-- | Like 'writeWith' but uses the experimental 'Refold' API.
521{-# INLINE writerWith #-}
522writerWith :: MonadIO m => Int -> Refold m Handle Word8 ()
524 FL.refoldMany (FL.take n $ A.unsafePinnedCreateOf n) chunkWriter
526-- | Write a byte stream to a file handle. Accumulates the input in chunks of
527-- up to 'Streamly.Internal.Data.Array.Type.defaultChunkSize' before writing
530-- >>> write = Handle.writeWith IO.defaultChunkSize
533write :: MonadIO m => Handle -> Fold m Word8 ()
534write = writeWith defaultChunkSize
536-- | Like 'write' but uses the experimental 'Refold' API.
540writer :: MonadIO m => Refold m Handle Word8 ()
541writer = writerWith defaultChunkSize
543-- XXX mmap a file into an array. This could be useful for in-place operations
544-- on a file. For example, we can quicksort the contents of a file by mmapping
547-------------------------------------------------------------------------------
548-- IO with encoding/decoding Unicode characters
549-------------------------------------------------------------------------------
553-- > readUtf8 = decodeUtf8 . read
555-- Read a UTF8 encoded stream of unicode characters from a file handle.
557{-# INLINE readUtf8 #-}
558readUtf8 :: MonadIO m => Handle -> Stream m Char
559readUtf8 = decodeUtf8 . read
562-- > writeUtf8 h s = write h $ encodeUtf8 s
564-- Encode a stream of unicode characters to UTF8 and write it to the given file
565-- handle. Default block buffering applies to the writes.
567{-# INLINE writeUtf8 #-}
568writeUtf8 :: MonadIO m => Handle -> Stream m Char -> m ()
569writeUtf8 h s = write h $ encodeUtf8 s
571-- | Write a stream of unicode characters after encoding to UTF-8 in chunks
572-- separated by a linefeed character @'\n'@. If the size of the buffer exceeds
573-- @defaultChunkSize@ and a linefeed is not yet found, the buffer is written
574-- anyway. This is similar to writing to a 'Handle' with the 'LineBuffering'
577{-# INLINE writeUtf8ByLines #-}
578writeUtf8ByLines :: MonadIO m => Handle -> Stream m Char -> m ()
579writeUtf8ByLines = undefined
581-- | Read UTF-8 lines from a file handle and apply the specified fold to each
582-- line. This is similar to reading a 'Handle' with the 'LineBuffering' option.
584{-# INLINE readLines #-}
585readLines :: MonadIO m => Handle -> Fold m Char b -> Stream m b
586readLines h f = foldLines (readUtf8 h) f
588-------------------------------------------------------------------------------
589-- Framing on a sequence
590-------------------------------------------------------------------------------
592-- | Read a stream from a file handle and split it into frames delimited by
593-- the specified sequence of elements. The supplied fold is applied on each
596{-# INLINE readFrames #-}
597readFrames :: (MonadIO m, Unboxed a)
598 => Array a -> Handle -> Fold m a b -> Stream m b
599readFrames = undefined -- foldFrames . read
601-- | Write a stream to the given file handle buffering up to frames separated
602-- by the given sequence or up to a maximum of @defaultChunkSize@.
604{-# INLINE writeByFrames #-}
605writeByFrames :: (MonadIO m, Unboxed a)
606 => Array a -> Handle -> Stream m a -> m ()
607writeByFrames = undefined
609-------------------------------------------------------------------------------
611-------------------------------------------------------------------------------
613-- | Write collecting the input in sessions of n seconds or if chunkSize
615{-# INLINE writeByChunksOrSessionsOf #-}
616writeByChunksOrSessionsOf :: MonadIO m
617 => Int -> Double -> Handle -> Stream m Word8 -> m ()
618writeByChunksOrSessionsOf chunkSize sessionSize h m = undefined
620-- | Write collecting the input in sessions of n seconds or if defaultChunkSize
622{-# INLINE writeBySessionsOf #-}
623writeBySessionsOf :: MonadIO m => Double -> Handle -> Stream m Word8 -> m ()
624writeBySessionsOf n = writeByChunksOrSessionsOf defaultChunkSize n
626-------------------------------------------------------------------------------
627-- Random Access IO (Seek)
628-------------------------------------------------------------------------------
630-- XXX handles could be shared, so we may not want to use the handle state at
631-- all for these APIs. we can use pread and pwrite instead. On windows we will
632-- need to use readFile/writeFile with an offset argument.
634-------------------------------------------------------------------------------
636-- | Read the element at the given index treating the file as an array.
638{-# INLINE readIndex #-}
639readIndex :: Unboxed a => Handle -> Int -> Maybe a
640readIndex arr i = undefined
642-- NOTE: To represent a range to read we have chosen (start, size) instead of
643-- (start, end). This helps in removing the ambiguity of whether "end" is
644-- included in the range or not.
646-- We could avoid specifying the range to be read and instead use "take size"
647-- on the stream, but it may end up reading more and then consume it partially.
649-- | @readSliceWith chunkSize handle pos len@ reads up to @len@ bytes
650-- from @handle@ starting at the offset @pos@ from the beginning of the file.
652-- Reads are performed in chunks of size @chunkSize@. For block devices, to
653-- avoid reading partial blocks @chunkSize@ must align with the block size of
654-- the underlying device. If the underlying block size is unknown, it is a good
655-- idea to keep it a multiple 4KiB. This API ensures that the start of each
656-- chunk is aligned with @chunkSize@ from second chunk onwards.
658{-# INLINE readSliceWith #-}
659readSliceWith :: (MonadIO m, Unboxed a)
660 => Int -> Handle -> Int -> Int -> Stream m a
661readSliceWith chunkSize h pos len = undefined
663-- | @readSlice h i count@ streams a slice from the file handle @h@ starting
664-- at index @i@ and reading up to @count@ elements in the forward direction
665-- ending at the index @i + count - 1@.
667{-# INLINE readSlice #-}
668readSlice :: (MonadIO m, Unboxed a)
669 => Handle -> Int -> Int -> Stream m a
670readSlice = readSliceWith A.defaultChunkSize
672-- | @readSliceRev h i count@ streams a slice from the file handle @h@ starting
673-- at index @i@ and reading up to @count@ elements in the reverse direction
674-- ending at the index @i - count + 1@.
676{-# INLINE readSliceRev #-}
677readSliceRev :: (MonadIO m, Unboxed a)
678 => Handle -> Int -> Int -> Stream m a
679readSliceRev h i count = undefined
681-- | Write the given element at the given index in the file.
683{-# INLINE writeIndex #-}
684writeIndex :: (MonadIO m, Unboxed a) => Handle -> Int -> a -> m ()
685writeIndex h i a = undefined
687-- | @writeSlice h i count stream@ writes a stream to the file handle @h@
688-- starting at index @i@ and writing up to @count@ elements in the forward
689-- direction ending at the index @i + count - 1@.
691{-# INLINE writeSlice #-}
692writeSlice :: (Monad m, Unboxed a)
693 => Handle -> Int -> Int -> Stream m a -> m ()
694writeSlice h i len s = undefined
696-- | @writeSliceRev 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 reverse
698-- direction ending at the index @i - count + 1@.
700{-# INLINE writeSliceRev #-}
701writeSliceRev :: (Monad m, Unboxed a)
702 => Handle -> Int -> Int -> Stream m a -> m ()
703writeSliceRev 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