This project is read-only.

Async Implementations of GZipStream and DeflateStream

Jun 17, 2010 at 7:56 PM

Hi, I'm wondering why GZipStream and DeflateStream do not have asynchronous implementations. They're relying on the Stream.BeginXXX implementations, which are not optimal (they perform an asynchronous delegate invocation of Read).

Is there a version that has explicit asynchronous APIs? We'd love to be able to use them in our scenario.


Jun 17, 2010 at 11:56 PM

No - you've seen the implementation. That's all there is.

Jun 18, 2010 at 12:10 AM

Yes I have. Are there plans to create async APIs? The reason I ask is that these could be used with a backing network stream having GZIPped http traffic.

If there aren't any plans to update the classes, I'll check other options. Otherwise, I'd wait for an update.


Jun 18, 2010 at 12:25 AM

no, no plans to extend it with a custom async implementation.

I'd definitely be interested in your benchmark results showing the difference.  Also, if you build one, please do contribute it to the project.


Sep 26, 2013 at 1:33 AM
I don't know, but here is a simple and inefficient implementation of read:
public static class ZipEx
        public static Task<ZipFile> Read(string file, CancellationToken token, IProgress<ReadProgressEventArgs> progress)
            var t = new TaskCompletionSource<ZipFile>();
            new Thread(() =>
                using (token.Register(() => t.TrySetCanceled()))
                        var opts = new ReadOptions();
                        opts.ReadProgress = (o, e) => progress.Report(e);
                        t.TrySetResult(ZipFile.Read(file, opts));
                    catch(Exception ex)
            }) { IsBackground = true }.Start();
            return t.Task;
I am going to do save and extract next.