Skip to content

Instantly share code, notes, and snippets.

@ksysiekj
Created March 25, 2017 22:37
Show Gist options
  • Save ksysiekj/fd0d1559c6fd242c769ac4f11bd15a2f to your computer and use it in GitHub Desktop.
Save ksysiekj/fd0d1559c6fd242c769ac4f11bd15a2f to your computer and use it in GitHub Desktop.
private abstract class CompressionService : ICompressionService
{
public abstract string EncodingType { get; }
protected abstract Stream CreateCompressionStream(Stream output);
protected abstract Stream CreateDecompressionStream(Stream input);
public Task Compress(Stream source, Stream destination)
{
Stream compressed = CreateCompressionStream(destination);
return Pump(source, compressed)
.ContinueWith(task => compressed.Dispose());
}
public Task Decompress(Stream source, Stream destination)
{
Stream decompressed = CreateDecompressionStream(source);
return Pump(decompressed, destination)
.ContinueWith(task => decompressed.Dispose());
}
private Task Pump(Stream input, Stream output)
{
return input.CopyToAsync(output);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment