conduit-algorithms- Conduit-based algorithms

Copyright2013-2017 Luis Pedro Coelho
Safe HaskellNone



Higher level async processing interfaces.



conduitPossiblyCompressedFile :: (MonadBaseControl IO m, MonadResource m) => FilePath -> Source m ByteString Source #

If the filename indicates a gzipped file (or, on Unix, also a bz2 file), then it reads it and uncompresses it.

On Windows, attempting to read from a bzip2 file, results in error.

For the case of gzip, asyncGzipFromFile is used.

asyncMapC Source #


:: (MonadIO m, NFData b) 
=> Int

Maximum number of worker threads

-> (a -> b)

Function to execute

-> Conduit a m b 

This is like map, except that each element is processed in a separate thread (up to maxThreads can be queued up at any one time). Results are evaluated to normal form (not weak-head normal form!, i.e., the structure is deeply evaluated) to ensure that the computation is fully evaluated in the worker thread.

Note that there is some overhead in threading. It is often a good idea to build larger chunks of input before passing it to asyncMapC to amortize the costs. That is, when f is not a lot of work, instead of asyncMapC f, it is sometimes better to do

   CC.conduitVector 4096 .| asyncMapC ( f) .| CC.concat

where CC refers to Combinators

asyncMapEitherC :: forall a m b e. (MonadIO m, NFData b, NFData e, MonadError e m) => Int -> (a -> Either e b) -> Conduit a m b Source #

asyncMapC with error handling. The inner function can now return an error (as a Left). When the first error is seen, it throwErrors in the main monad. Note that f may be evaluated for arguments beyond the first error (as some threads may be running in the background and already processing elements after the first error).

See asyncMapC

asyncGzipTo :: forall m. (MonadIO m, MonadBaseControl IO m) => Handle -> Sink ByteString m () Source #

A simple sink which performs gzip compression in a separate thread and writes the results to h.

See also asyncGzipToFile

asyncGzipToFile :: forall m. (MonadResource m, MonadBaseControl IO m) => FilePath -> Sink ByteString m () Source #

Compresses the output and writes to the given file with compression being performed in a separate thread.

See also asyncGzipTo

asyncGzipFrom :: forall m. (MonadIO m, MonadResource m, MonadBaseControl IO m) => Handle -> Source m ByteString Source #

A source which produces the ungzipped content from the the given handle. Note that this "reads ahead" so if you do not use all the input, the Handle will probably be left at an undefined position in the file.

See also asyncGzipFromFile

asyncGzipFromFile :: forall m. (MonadResource m, MonadBaseControl IO m) => FilePath -> Source m ByteString Source #

Open and read a gzip file with the uncompression being performed in a separate thread.

See also asyncGzipFrom