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.Unboxed (Unboxed)
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.Unboxed.Type
126 (Array(..), writeNUnsafe, unsafeFreezeWithShrink, byteLength)
127import Streamly.Internal.Data.Stream.Type (Stream)
128import Streamly.Internal.Data.Array.Unboxed.Stream (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.Unboxed as A
134import qualified Streamly.Internal.Data.Array.Unboxed.Type as A
135import qualified Streamly.Internal.Data.Array.Unboxed.Stream as AS
136import qualified Streamly.Internal.Data.Array.Unboxed.Mut.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.Unboxed as Array
147-- >>> import qualified Streamly.Data.Fold as Fold
148-- >>> import qualified Streamly.Data.Unfold as Unfold
149-- >>> import qualified Streamly.Prelude as Stream
151-- >>> import qualified Streamly.Internal.Data.Array.Unboxed.Type as Array (writeNUnsafe)
152-- >>> import qualified Streamly.Internal.Data.Stream.IsStream 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.
181{-# INLINABLE getChunk #-}
182getChunk :: MonadIO m => Int -> Handle -> m (Array Word8)
183getChunk size h = liftIO $ do
184 arr <- MArray.newPinnedBytes size
185 -- ptr <- mallocPlainForeignPtrAlignedBytes size (alignment (undefined :: Word8))
186 MArray.asPtrUnsafe arr $ \p -> do
187 n <- hGetBufSome h p size
188 -- XXX shrink only if the diff is significant
190 unsafeFreezeWithShrink $
191 arr { MArray.arrEnd = n, MArray.arrBound = size }
193-- This could be useful in implementing the "reverse" read APIs or if you want
194-- to read arrays of exact size instead of compacting them later. Compacting
195-- later requires more copying.
197-- | Read a 'ByteArray' consisting of exactly the specified number of bytes
198-- from a file handle.
201{-# INLINABLE getChunkOf #-}
202getChunkOf :: Int -> Handle -> IO (Array Word8)
203getChunkOf = undefined
205-------------------------------------------------------------------------------
206-- Stream of Arrays IO
207-------------------------------------------------------------------------------
209-- | @getChunksWith size h@ reads a stream of arrays from file handle @h@.
210-- The maximum size of a single array is specified by @size@. The actual size
211-- read may be less than or equal to @size@.
213{-# INLINE _getChunksWith #-}
214_getChunksWith :: MonadIO m => Int -> Handle -> Stream m (Array Word8)
215_getChunksWith size h = S.fromStreamK go
217 -- XXX use cons/nil instead
218 go = K.mkStream $ \_ yld _ stp -> do
219 arr <- getChunk size h
220 if byteLength arr == 0
224-- | @readChunksWith size handle@ reads a stream of arrays from the file
225-- handle @handle@. The maximum size of a single array is limited to @size@.
226-- The actual size read may be less than or equal to @size@.
228-- >>> readChunksWith size h = Stream.unfold Handle.chunkReaderWith (size, h)
231{-# INLINE_NORMAL readChunksWith #-}
232readChunksWith :: MonadIO m => Int -> Handle -> Stream m (Array Word8)
233readChunksWith size h = S.fromStreamD (D.Stream step ())
235 {-# INLINE_LATE step #-}
237 arr <- getChunk size h
239 case byteLength arr of
243-- | Unfold the tuple @(bufsize, handle)@ into a stream of 'Word8' arrays.
244-- Read requests to the IO device are performed using a buffer of size
245-- @bufsize@. The size of an array in the resulting stream is always less than
246-- or equal to @bufsize@.
249{-# INLINE_NORMAL chunkReaderWith #-}
250chunkReaderWith :: MonadIO m => Unfold m (Int, Handle) (Array Word8)
252 UF.lmap (uncurry getChunk) UF.repeatM
253 & UF.takeWhile ((/= 0) . byteLength)
255-- | Same as 'chunkReaderWith'
258{-# DEPRECATED readChunksWithBufferOf "Please use chunkReaderWith instead." #-}
259{-# INLINE_NORMAL readChunksWithBufferOf #-}
260readChunksWithBufferOf :: MonadIO m => Unfold m (Int, Handle) (Array Word8)
261readChunksWithBufferOf = chunkReaderWith
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`.
274{-# INLINE_NORMAL chunkReaderFromToWith #-}
275chunkReaderFromToWith :: MonadIO m =>
276 Unfold m (Int, Int, Int, Handle) (Array Word8)
277chunkReaderFromToWith = Unfold step inject
281 inject (from, to, bufSize, h) = do
282 liftIO $ hSeek h AbsoluteSeek $ fromIntegral from
283 -- XXX Use a strict Tuple?
284 return (to - from + 1, bufSize, h)
286 {-# INLINE_LATE step #-}
287 step (remaining, bufSize, h) =
291 arr <- getChunk (min bufSize remaining) h
293 case byteLength arr of
296 assert (len <= remaining)
297 $ D.Yield arr (remaining - len, bufSize, h)
299-- | @getChunks handle@ reads a stream of arrays from the specified file
300-- handle. The maximum size of a single array is limited to
301-- @defaultChunkSize@. The actual size read may be less than or equal to
302-- @defaultChunkSize@.
304-- >>> readChunks = Handle.readChunksWith IO.defaultChunkSize
307{-# INLINE readChunks #-}
308readChunks :: MonadIO m => Handle -> Stream m (Array Word8)
309readChunks = readChunksWith defaultChunkSize
311-- | Unfolds a handle into a stream of 'Word8' arrays. Requests to the IO
312-- device are performed using a buffer of size
313-- 'Streamly.Internal.Data.Array.Unboxed.Type.defaultChunkSize'. The
314-- size of arrays in the resulting stream are therefore less than or equal to
315-- 'Streamly.Internal.Data.Array.Unboxed.Type.defaultChunkSize'.
317-- >>> chunkReader = Unfold.first IO.defaultChunkSize Handle.chunkReaderWith
320{-# INLINE chunkReader #-}
321chunkReader :: MonadIO m => Unfold m Handle (Array Word8)
322chunkReader = UF.first defaultChunkSize chunkReaderWith
324-------------------------------------------------------------------------------
325-- Read File to Stream
326-------------------------------------------------------------------------------
328-- TODO for concurrent streams implement readahead IO. We can send multiple
329-- read requests at the same time. For serial case we can use async IO. We can
330-- also control the read throughput in mbps or IOPS.
332-- | Unfolds the tuple @(bufsize, handle)@ into a byte stream, read requests
333-- to the IO device are performed using buffers of @bufsize@.
335-- >>> readerWith = Unfold.many Array.reader Handle.chunkReaderWith
338{-# INLINE readerWith #-}
339readerWith :: MonadIO m => Unfold m (Int, Handle) Word8
340readerWith = UF.many A.reader chunkReaderWith
342-- | Same as 'readerWith'
345{-# DEPRECATED readWithBufferOf "Please use 'readerWith' instead." #-}
346{-# INLINE readWithBufferOf #-}
347readWithBufferOf :: MonadIO m => Unfold m (Int, Handle) Word8
348readWithBufferOf = readerWith
350-- | @readWith bufsize handle@ reads a byte stream from a file
351-- handle, reads are performed in chunks of up to @bufsize@.
353-- >>> readWith size h = Stream.unfoldMany Array.reader $ Handle.readChunksWith size h
356{-# INLINE readWith #-}
357readWith :: MonadIO m => Int -> Handle -> Stream m Word8
358readWith size h = AS.concat $ readChunksWith size h
360-- | Unfolds a file handle into a byte stream. IO requests to the device are
361-- performed in sizes of
362-- 'Streamly.Internal.Data.Array.Unboxed.Type.defaultChunkSize'.
364-- >>> reader = Unfold.many Array.reader chunkReader
368reader :: MonadIO m => Unfold m Handle Word8
369reader = UF.many A.reader chunkReader
371-- | Generate a byte stream from a file 'Handle'.
373-- >>> read h = Stream.unfoldMany Array.reader $ Handle.readChunks h
377read :: MonadIO m => Handle -> Stream m Word8
378read = AS.concat . readChunks
380-------------------------------------------------------------------------------
382-------------------------------------------------------------------------------
384-------------------------------------------------------------------------------
386-------------------------------------------------------------------------------
388-- | Write an 'Array' to a file handle.
391{-# INLINABLE putChunk #-}
392putChunk :: MonadIO m => Handle -> Array a -> m ()
393putChunk _ arr | byteLength arr == 0 = return ()
394putChunk h arr = A.asPtrUnsafe arr $ \ptr ->
395 liftIO $ hPutBuf h ptr aLen
399 -- XXX We should have the length passed by asPtrUnsafe itself.
400 aLen = A.byteLength arr
402-------------------------------------------------------------------------------
403-- Stream of Arrays IO
404-------------------------------------------------------------------------------
406-------------------------------------------------------------------------------
408-------------------------------------------------------------------------------
410-- XXX use an unfold to fromObjects or fromUnfold so that we can put any object
411-- | Write a stream of arrays to a handle.
413-- >>> putChunks h = Stream.mapM_ (Handle.putChunk h)
416{-# INLINE putChunks #-}
417putChunks :: MonadIO m => Handle -> Stream m (Array a) -> m ()
418putChunks h = S.fold (FL.drainBy (putChunk h))
420-- XXX AS.compact can be written idiomatically in terms of foldMany, just like
421-- AS.concat is written in terms of foldMany. Once that is done we can write
422-- idiomatic def in the docs.
424-- | @putChunksWith bufsize handle stream@ writes a stream of arrays
425-- to @handle@ after coalescing the adjacent arrays in chunks of @bufsize@.
426-- The chunk size is only a maximum and the actual writes could be smaller as
427-- we do not split the arrays to fit exactly to the specified size.
430{-# INLINE putChunksWith #-}
431putChunksWith :: (MonadIO m, Unboxed a)
432 => Int -> Handle -> Stream m (Array a) -> m ()
433putChunksWith n h xs = putChunks h $ AS.compact n xs
435-- | @putBytesWith bufsize handle stream@ writes @stream@ to @handle@
436-- in chunks of @bufsize@. A write is performed to the IO device as soon as we
437-- collect the required input size.
439-- >>> putBytesWith n h m = Handle.putChunks h $ Stream.arraysOf n m
442{-# INLINE putBytesWith #-}
443putBytesWith :: MonadIO m => Int -> Handle -> Stream m Word8 -> m ()
444putBytesWith n h m = putChunks h $ S.arraysOf n m
446-- putBytesWith n h m = putChunks h $ AS.arraysOf n m
448-- | Write a byte stream to a file handle. Accumulates the input in chunks of
449-- up to 'Streamly.Internal.Data.Array.Unboxed.Type.defaultChunkSize' before writing.
451-- NOTE: This may perform better than the 'write' fold, you can try this if you
452-- need some extra perf boost.
454-- >>> putBytes = Handle.putBytesWith IO.defaultChunkSize
457{-# INLINE putBytes #-}
458putBytes :: MonadIO m => Handle -> Stream m Word8 -> m ()
459putBytes = putBytesWith defaultChunkSize
461-- | Write a stream of arrays to a handle. Each array in the stream is written
462-- to the device as a separate IO request.
464-- writeChunks h = Fold.drainBy (Handle.putChunk h)
467{-# INLINE writeChunks #-}
468writeChunks :: MonadIO m => Handle -> Fold m (Array a) ()
469writeChunks h = FL.drainBy (putChunk h)
471-- | Like writeChunks but uses the experimental 'Refold' API.
474{-# INLINE chunkWriter #-}
475chunkWriter :: MonadIO m => Refold m Handle (Array a) ()
476chunkWriter = Refold.drainBy putChunk
478-- XXX lpackArraysChunksOf should be written idiomatically
480-- | @writeChunksWith bufsize handle@ writes a stream of arrays
481-- to @handle@ after coalescing the adjacent arrays in chunks of @bufsize@.
482-- We never split an array, if a single array is bigger than the specified size
483-- it emitted as it is. Multiple arrays are coalesed as long as the total size
484-- remains below the specified size.
487{-# INLINE writeChunksWith #-}
488writeChunksWith :: (MonadIO m, Unboxed a)
489 => Int -> Handle -> Fold m (Array a) ()
490writeChunksWith n h = lpackArraysChunksOf n (writeChunks h)
492-- | Same as 'writeChunksWith'
495{-# DEPRECATED writeChunksWithBufferOf "Please use writeChunksWith instead." #-}
496{-# INLINE writeChunksWithBufferOf #-}
497writeChunksWithBufferOf :: (MonadIO m, Unboxed a)
498 => Int -> Handle -> Fold m (Array a) ()
499writeChunksWithBufferOf = writeChunksWith
501-- GHC buffer size dEFAULT_FD_BUFFER_SIZE=8192 bytes.
504-- Note that if you use a chunk size less than 8K (GHC's default buffer
505-- size) then you are advised to use 'NOBuffering' mode on the 'Handle' in case you
506-- do not want buffering to occur at GHC level as well. Same thing applies to
509-- XXX Maybe we should have a Fold.arraysOf like we have Stream.arraysOf
511-- | @writeWith reqSize handle@ writes the input stream to @handle@.
512-- Bytes in the input stream are collected into a buffer until we have a chunk
513-- of @reqSize@ and then written to the IO device.
515-- >>> writeWith n h = Fold.chunksOf n (Array.writeNUnsafe n) (Handle.writeChunks h)
518{-# INLINE writeWith #-}
519writeWith :: MonadIO m => Int -> Handle -> Fold m Word8 ()
520writeWith n h = FL.chunksOf n (writeNUnsafe n) (writeChunks h)
522-- | Same as 'writeWith'
525{-# DEPRECATED writeWithBufferOf "Please use writeWith instead." #-}
526{-# INLINE writeWithBufferOf #-}
527writeWithBufferOf :: MonadIO m => Int -> Handle -> Fold m Word8 ()
528writeWithBufferOf = writeWith
530-- | Write a stream of 'Maybe' values. Keep buffering the just values in an
531-- array until a 'Nothing' is encountered or the buffer size exceeds the
532-- specified limit, at that point flush the buffer to the handle.
535{-# INLINE writeMaybesWith #-}
536writeMaybesWith :: (MonadIO m )
537 => Int -> Handle -> Fold m (Maybe Word8) ()
539 let writeNJusts = FL.lmap fromJust $ A.writeN n
540 writeOnNothing = FL.takeEndBy_ isNothing writeNJusts
541 in FL.many writeOnNothing (writeChunks h)
543-- | Like 'writeWith' but uses the experimental 'Refold' API.
546{-# INLINE writerWith #-}
547writerWith :: MonadIO m => Int -> Refold m Handle Word8 ()
549 FL.refoldMany (FL.take n $ writeNUnsafe n) chunkWriter
551-- | Write a byte stream to a file handle. Accumulates the input in chunks of
552-- up to 'Streamly.Internal.Data.Array.Unboxed.Type.defaultChunkSize' before writing
555-- >>> write = Handle.writeWith IO.defaultChunkSize
559write :: MonadIO m => Handle -> Fold m Word8 ()
560write = writeWith defaultChunkSize
562-- | Like 'write' but uses the experimental 'Refold' API.
566writer :: MonadIO m => Refold m Handle Word8 ()
567writer = writerWith defaultChunkSize
569-- XXX mmap a file into an array. This could be useful for in-place operations
570-- on a file. For example, we can quicksort the contents of a file by mmapping
573-------------------------------------------------------------------------------
574-- IO with encoding/decoding Unicode characters
575-------------------------------------------------------------------------------
579-- > readUtf8 = decodeUtf8 . read
581-- Read a UTF8 encoded stream of unicode characters from a file handle.
584{-# INLINE readUtf8 #-}
585readUtf8 :: MonadIO m => Handle -> Stream m Char
586readUtf8 = decodeUtf8 . read
589-- > writeUtf8 h s = write h $ encodeUtf8 s
591-- Encode a stream of unicode characters to UTF8 and write it to the given file
592-- handle. Default block buffering applies to the writes.
595{-# INLINE writeUtf8 #-}
596writeUtf8 :: MonadIO m => Handle -> Stream m Char -> m ()
597writeUtf8 h s = write h $ encodeUtf8 s
599-- | Write a stream of unicode characters after encoding to UTF-8 in chunks
600-- separated by a linefeed character @'\n'@. If the size of the buffer exceeds
601-- @defaultChunkSize@ and a linefeed is not yet found, the buffer is written
602-- anyway. This is similar to writing to a 'Handle' with the 'LineBuffering'
606{-# INLINE writeUtf8ByLines #-}
607writeUtf8ByLines :: MonadIO m => Handle -> Stream m Char -> m ()
608writeUtf8ByLines = undefined
610-- | Read UTF-8 lines from a file handle and apply the specified fold to each
611-- line. This is similar to reading a 'Handle' with the 'LineBuffering' option.
614{-# INLINE readLines #-}
615readLines :: MonadIO m => Handle -> Fold m Char b -> Stream m b
616readLines h f = foldLines (readUtf8 h) f
618-------------------------------------------------------------------------------
619-- Framing on a sequence
620-------------------------------------------------------------------------------
622-- | Read a stream from a file handle and split it into frames delimited by
623-- the specified sequence of elements. The supplied fold is applied on each
627{-# INLINE readFrames #-}
628readFrames :: (MonadIO m, Unboxed a)
629 => Array a -> Handle -> Fold m a b -> Stream m b
630readFrames = undefined -- foldFrames . read
632-- | Write a stream to the given file handle buffering up to frames separated
633-- by the given sequence or up to a maximum of @defaultChunkSize@.
636{-# INLINE writeByFrames #-}
637writeByFrames :: (MonadIO m, Unboxed a)
638 => Array a -> Handle -> Stream m a -> m ()
639writeByFrames = undefined
641-------------------------------------------------------------------------------
643-------------------------------------------------------------------------------
645-- | Write collecting the input in sessions of n seconds or if chunkSize
647{-# INLINE writeByChunksOrSessionsOf #-}
648writeByChunksOrSessionsOf :: MonadIO m
649 => Int -> Double -> Handle -> Stream m Word8 -> m ()
650writeByChunksOrSessionsOf chunkSize sessionSize h m = undefined
652-- | Write collecting the input in sessions of n seconds or if defaultChunkSize
654{-# INLINE writeBySessionsOf #-}
655writeBySessionsOf :: MonadIO m => Double -> Handle -> Stream m Word8 -> m ()
656writeBySessionsOf n = writeByChunksOrSessionsOf defaultChunkSize n
658-------------------------------------------------------------------------------
659-- Random Access IO (Seek)
660-------------------------------------------------------------------------------
662-- XXX handles could be shared, so we may not want to use the handle state at
663-- all for these APIs. we can use pread and pwrite instead. On windows we will
664-- need to use readFile/writeFile with an offset argument.
666-------------------------------------------------------------------------------
668-- | Read the element at the given index treating the file as an array.
671{-# INLINE readIndex #-}
672readIndex :: Unboxed a => Handle -> Int -> Maybe a
673readIndex arr i = undefined
675-- NOTE: To represent a range to read we have chosen (start, size) instead of
676-- (start, end). This helps in removing the ambiguity of whether "end" is
677-- included in the range or not.
679-- We could avoid specifying the range to be read and instead use "take size"
680-- on the stream, but it may end up reading more and then consume it partially.
682-- | @readSliceWith chunkSize handle pos len@ reads up to @len@ bytes
683-- from @handle@ starting at the offset @pos@ from the beginning of the file.
685-- Reads are performed in chunks of size @chunkSize@. For block devices, to
686-- avoid reading partial blocks @chunkSize@ must align with the block size of
687-- the underlying device. If the underlying block size is unknown, it is a good
688-- idea to keep it a multiple 4KiB. This API ensures that the start of each
689-- chunk is aligned with @chunkSize@ from second chunk onwards.
691{-# INLINE readSliceWith #-}
692readSliceWith :: (MonadIO m, Unboxed a)
693 => Int -> Handle -> Int -> Int -> Stream m a
694readSliceWith chunkSize h pos len = undefined
696-- | @readSlice h i count@ streams a slice from the file handle @h@ starting
697-- at index @i@ and reading up to @count@ elements in the forward direction
698-- ending at the index @i + count - 1@.
701{-# INLINE readSlice #-}
702readSlice :: (MonadIO m, Unboxed a)
703 => Handle -> Int -> Int -> Stream m a
704readSlice = readSliceWith A.defaultChunkSize
706-- | @readSliceRev h i count@ streams a slice from the file handle @h@ starting
707-- at index @i@ and reading up to @count@ elements in the reverse direction
708-- ending at the index @i - count + 1@.
711{-# INLINE readSliceRev #-}
712readSliceRev :: (MonadIO m, Unboxed a)
713 => Handle -> Int -> Int -> Stream m a
714readSliceRev h i count = undefined
716-- | Write the given element at the given index in the file.
719{-# INLINE writeIndex #-}
720writeIndex :: (MonadIO m, Unboxed a) => Handle -> Int -> a -> m ()
721writeIndex h i a = undefined
723-- | @writeSlice h i count stream@ writes a stream to the file handle @h@
724-- starting at index @i@ and writing up to @count@ elements in the forward
725-- direction ending at the index @i + count - 1@.
728{-# INLINE writeSlice #-}
729writeSlice :: (Monad m, Unboxed a)
730 => Handle -> Int -> Int -> Stream m a -> m ()
731writeSlice h i len s = undefined
733-- | @writeSliceRev h i count stream@ writes a stream to the file handle @h@
734-- starting at index @i@ and writing up to @count@ elements in the reverse
735-- direction ending at the index @i - count + 1@.
738{-# INLINE writeSliceRev #-}
739writeSliceRev :: (Monad m, Unboxed a)
740 => Handle -> Int -> Int -> Stream m a -> m ()
741writeSliceRev 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