snoyberg/zlib-bindings — Issue #2: Need control over flushing semantics
Author: gregorycollins
Created: 2011-10-10 13:15:28+00:00
State: open

Hi Michael,

I recently ran into this problem when trying to write some interactive tests using Snap + gzip output. Consider a toy enumerator like this:

trickleOutput :: Int -> Enumerator Builder IO a
trickleOutput n = concatEnums $ dots `interleave` delays
where
enumOne = enumList 1 [fromByteString ".\n", flush]
delay st = do
liftIO $ threadDelay 1000000
returnI st

interleave x0 y0 = (go id x0 y0) []
where
go !dl [] ys = dl . (++ys)
go !dl xs [] = dl . (++xs)
go !dl (x:xs) (y:ys) = go (dl . (x:) . (y:)) xs ys

dots = replicate n enumOne
delays = replicate n delay

This enumerates ".\n" followed by a "flush" every second, for N seconds. I want the "flush" to be immediately reflected in the gzipped output (this has implications, for example, for long-polling with AJAX), but this isn't possible with zlib-bindings at the moment. Basically: I think we need a version of "withDeflateInput" that allows you to get at Z_SYNC_FLUSH. What do you think?