snap-core-0.2.1: Snap: A Haskell Web Framework (Core)

Snap.Iteratee

Contents

Description

Snap Framework type aliases and utilities for iteratees. Note that as a convenience, this module also exports everything from Data.Iteratee in the iteratee library.

WARNING: Note that all of these types are scheduled to change in the darcs head version of the iteratee library; John Lato et al. are working on a much improved iteratee formulation.

Synopsis

Convenience aliases around types from Data.Iteratee

type Enumerator m a = Iteratee m a -> m (Iteratee m a)Source

Re-export types and functions from Data.Iteratee

Helper functions

Enumerators

enumBS :: Monad m => ByteString -> Enumerator m aSource

Enumerates a strict bytestring.

enumLBS :: Monad m => ByteString -> Enumerator m aSource

Enumerates a lazy bytestring.

Conversion to/from WrappedByteString

fromWrap :: WrappedByteString Word8 -> ByteStringSource

Converts a wrapped bytestring to a lazy bytestring.

toWrap :: ByteString -> WrappedByteString Word8Source

Converts a lazy bytestring to a wrapped bytestring.

Iteratee utilities

takeExactly :: (StreamChunk s el, Monad m) => Int -> EnumeratorN s el s el m aSource

Reads n elements from a stream and applies the given iteratee to the stream of the read elements. Reads exactly n elements, and if the stream is short propagates an error.

takeNoMoreThan :: (StreamChunk s el, Monad m) => Int -> EnumeratorN s el s el m aSource

Reads up to n elements from a stream and applies the given iteratee to the stream of the read elements. If more than n elements are read, propagates an error.

countBytes :: Monad m => Iteratee m a -> Iteratee m (a, Int)Source

Wraps an Iteratee, counting the number of bytes consumed by it.

bufferIteratee :: Monad m => Enumerator m aSource

Buffers an iteratee.

Our enumerators produce a lot of little strings; rather than spending all our time doing kernel context switches for 4-byte write() calls, we buffer the iteratee to send 2KB at a time.