streaming-png-0.1.0.0: Perfectly streaming PNG image decoding

Copyright(c) Bradley Hardy 2016
LicenseLGPL3
Maintainerbradleyhardy@live.com
Stabilityexperimental
Portabilitynon-portable
Safe HaskellNone
LanguageHaskell2010

Codec.Picture.Png.Streaming.Util

Description

This is a set of assorted utility functions for streaming and streaming-bytestring which are used in various places in this library, but may also be of use to others so they are exposed here.

Synopsis

Documentation

expectNull :: (MonadThrow m, Exception e) => e -> ByteString m r -> m r Source

If the input ByteString is empty, return its result. Otherwise throw the provided error value.

chunksOfBS :: Monad m => Int64 -> ByteString m r -> Stream (ByteString m) m r Source

Split a streaming ByteString up into a stream of chunks of the given size.

rememberPrevious :: Monad m => Stream (Of a) m r -> Stream (Of (Maybe a, a)) m r Source

Remember the previous value at each point in a stream of values.

mapWithMemory :: forall m a b r. Monad m => (Maybe b -> a -> m b) -> Stream (Of a) m r -> Stream (Of b) m r Source

Map a function across a stream, but also include in its arguments the result of applying it to the previous item in the stream (which is Nothing if the current item is the first in the stream).

filterMapped :: (Monad m, Functor f, Functor g) => (forall x. f x -> m (Sum Identity g x)) -> Stream f m r -> Stream g m r Source

For each functor wrapper f in the stream, either strip it off or convert it to some new functor g. Return the stream of g's. This can be seen to be analogous to a list function of type Monad m => (a -> m (Maybe b)) -> [a] -> m [b] if we consider what it looks like when f and g are Of a and Of b respectively:

filterMapped
  :: (forall x. Of a x -> m (Sum Identity (Of b) x))
  -> Stream (Of a) m r -> Stream (Of b) m r

Here, Sum Identity (Of b) x is isomorphic to Of (Maybe b) x.

filtered :: (Monad m, Functor f) => (forall x. f x -> m (Maybe x)) -> Stream f m r -> Stream f m r Source

For each functor wrapper in the stream, optionally strip it off. Those stripped off will be removed from the resulting stream.

buildByteString :: Monad m => (a -> m (Either r (ByteString m (), a))) -> a -> ByteString m r Source

Build a ByteString monadically from a seed.

bytestringToVector :: ByteString -> Vector Word8 Source

Directly convert a ByteString into a storable Vector, in constant time.

vectorToBytestring :: Vector Word8 -> ByteString Source

Directly convert a storable Vector of Word8s into a ByteString, in constant time.