streamly-0.7.1: Beautiful Streaming, Concurrent and Reactive Composition

Copyright(c) 2018 Composewell Technologies
LicenseBSD3
Maintainerstreamly@composewell.com
Stabilityexperimental
PortabilityGHC
Safe HaskellNone
LanguageHaskell2010

Streamly.Internal.FileSystem.Handle

Contents

Description

 
Synopsis

Read from Handle

read :: MonadIO m => Unfold m Handle Word8 Source #

Unfolds a file handle into a byte stream. IO requests to the device are performed in sizes of defaultChunkSize.

Since: 0.7.0

readWithBufferOf :: MonadIO m => Unfold m (Int, Handle) Word8 Source #

Unfolds the tuple (bufsize, handle) into a byte stream, read requests to the IO device are performed using buffers of bufsize.

Since: 0.7.0

toBytes :: (IsStream t, MonadIO m) => Handle -> t m Word8 Source #

Generate a byte stream from a file Handle.

Internal

toBytesWithBufferOf :: (IsStream t, MonadIO m) => Int -> Handle -> t m Word8 Source #

toBytesWithBufferOf bufsize handle reads a byte stream from a file handle, reads are performed in chunks of up to bufsize.

Internal

getBytes :: (IsStream t, MonadIO m) => t m Word8 Source #

Read a stream of bytes from standard input.

getBytes = toBytes stdin

Internal

readChunks :: MonadIO m => Unfold m Handle (Array Word8) Source #

Unfolds a handle into a stream of Word8 arrays. Requests to the IO device are performed using a buffer of size defaultChunkSize. The size of arrays in the resulting stream are therefore less than or equal to defaultChunkSize.

Since: 0.7.0

readChunksWithBufferOf :: MonadIO m => Unfold m (Int, Handle) (Array Word8) Source #

Unfold the tuple (bufsize, handle) into a stream of Word8 arrays. Read requests to the IO device are performed using a buffer of size bufsize. The size of an array in the resulting stream is always less than or equal to bufsize.

Since: 0.7.0

toChunksWithBufferOf :: (IsStream t, MonadIO m) => Int -> Handle -> t m (Array Word8) Source #

toChunksWithBufferOf size handle reads a stream of arrays from the file handle handle. The maximum size of a single array is limited to size. The actual size read may be less than or equal to size.

Since: 0.7.0

toChunks :: (IsStream t, MonadIO m) => Handle -> t m (Array Word8) Source #

toChunks handle reads a stream of arrays from the specified file handle. The maximum size of a single array is limited to defaultChunkSize. The actual size read may be less than or equal to defaultChunkSize.

toChunks = toChunksWithBufferOf defaultChunkSize

Since: 0.7.0

getChunks :: (IsStream t, MonadIO m) => t m (Array Word8) Source #

Read a stream of chunks from standard input. The maximum size of a single chunk is limited to defaultChunkSize. The actual size read may be less than defaultChunkSize.

getChunks = toChunks stdin

Internal

Write to Handle

write :: MonadIO m => Handle -> Fold m Word8 () Source #

Write a byte stream to a file handle. Accumulates the input in chunks of up to defaultChunkSize before writing to the IO device.

Since: 0.7.0

writeWithBufferOf :: MonadIO m => Int -> Handle -> Fold m Word8 () Source #

writeWithBufferOf reqSize handle writes the input stream to handle. Bytes in the input stream are collected into a buffer until we have a chunk of reqSize and then written to the IO device.

Since: 0.7.0

fromBytes :: MonadIO m => Handle -> SerialT m Word8 -> m () Source #

Write a byte stream to a file handle. Accumulates the input in chunks of up to defaultChunkSize before writing.

NOTE: This may perform better than the write fold, you can try this if you need some extra perf boost.

Since: 0.7.0

fromBytesWithBufferOf :: MonadIO m => Int -> Handle -> SerialT m Word8 -> m () Source #

fromBytesWithBufferOf bufsize handle stream writes stream to handle in chunks of bufsize. A write is performed to the IO device as soon as we collect the required input size.

Since: 0.7.0

writeArray :: Storable a => Handle -> Array a -> IO () Source #

Write an Array to a file handle.

Since: 0.7.0

writeChunks :: (MonadIO m, Storable a) => Handle -> Fold m (Array a) () Source #

Write a stream of arrays to a handle. Each array in the stream is written to the device as a separate IO request.

Since: 0.7.0

writeChunksWithBufferOf :: (MonadIO m, Storable a) => Int -> Handle -> Fold m (Array a) () Source #

writeChunksWithBufferOf bufsize handle writes a stream of arrays to handle after coalescing the adjacent arrays in chunks of bufsize. We never split an array, if a single array is bigger than the specified size it emitted as it is. Multiple arrays are coalesed as long as the total size remains below the specified size.

Since: 0.7.0

fromChunksWithBufferOf :: (MonadIO m, Storable a) => Int -> Handle -> SerialT m (Array a) -> m () Source #

fromChunksWithBufferOf bufsize handle stream writes a stream of arrays to handle after coalescing the adjacent arrays in chunks of bufsize. The chunk size is only a maximum and the actual writes could be smaller as we do not split the arrays to fit exactly to the specified size.

Since: 0.7.0

fromChunks :: (MonadIO m, Storable a) => Handle -> SerialT m (Array a) -> m () Source #

Write a stream of arrays to a handle.

Since: 0.7.0

putChunks :: (MonadIO m, Storable a) => SerialT m (Array a) -> m () Source #

Write a stream of chunks to standard output.

Internal

putStrings :: MonadAsync m => (SerialT m Char -> SerialT m Word8) -> SerialT m String -> m () Source #

Write a stream of strings to standard output using the supplied encoding. Output is flushed to the device for each string.

Internal

putBytes :: MonadIO m => SerialT m Word8 -> m () Source #

Write a stream of bytes from standard output.

putBytes = fromBytes stdout

Internal

putLines :: MonadAsync m => (SerialT m Char -> SerialT m Word8) -> SerialT m String -> m () Source #

Write a stream of strings as separate lines to standard output using the supplied encoding. Output is line buffered i.e. the output is written to the device as soon as a newline is encountered.

Internal