Created
March 25, 2017 22:37
-
-
Save ksysiekj/fd0d1559c6fd242c769ac4f11bd15a2f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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