Skip to content

Commit

Permalink
Fix issue #75
Browse files Browse the repository at this point in the history
  • Loading branch information
geoperez committed May 31, 2017
1 parent b95326d commit 390dab3
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/Unosquare.Labs.EmbedIO.Command/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
},
"netcoreapp1.1": {
"dependencies": {
"Microsoft.NETCore.App": "1.1.1",
"Microsoft.NETCore.App": "1.1.2",
"System.Runtime.Loader": "4.3.0"
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Unosquare.Labs.EmbedIO.Samples/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"frameworks": {
"netcoreapp1.1": {
"dependencies": {
"Microsoft.NETCore.App": "1.1.1"
"Microsoft.NETCore.App": "1.1.2"
}
},
"net452": {
Expand Down
43 changes: 33 additions & 10 deletions src/Unosquare.Labs.EmbedIO/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -455,27 +455,50 @@ private static Dictionary<string, object> ParseFormDataAsDictionary(string reque
/// <param name="method">The method.</param>
/// <param name="mode">The mode.</param>
/// <returns></returns>
public static MemoryStream Compress(this Stream buffer, CompressionMethod method = CompressionMethod.Gzip, CompressionMode mode = CompressionMode.Compress)
public static MemoryStream Compress(this Stream buffer, CompressionMethod method = CompressionMethod.Gzip,
CompressionMode mode = CompressionMode.Compress)
{
buffer.Position = 0;
var targetStream = new MemoryStream();

switch (method)
{
case CompressionMethod.Deflate:
using (var compressor = new DeflateStream(targetStream, mode, true))
if (mode == CompressionMode.Compress)
{
buffer.CopyTo(compressor, 1024);
buffer.CopyTo(compressor);
// WebSocket use this
targetStream.Write(Last, 0, 1);
targetStream.Position = 0;
using (var compressor = new DeflateStream(targetStream, CompressionMode.Compress, true))
{
buffer.CopyTo(compressor, 1024);
buffer.CopyTo(compressor);
// WebSocket use this
targetStream.Write(Last, 0, 1);
targetStream.Position = 0;
}
}
else
{
using (var compressor = new DeflateStream(buffer, CompressionMode.Decompress))
{
compressor.CopyTo(targetStream);
}

}
break;
case CompressionMethod.Gzip:
using (var compressor = new GZipStream(targetStream, mode, true))
if (mode == CompressionMode.Compress)
{
buffer.CopyTo(compressor);
using (var compressor = new GZipStream(targetStream, CompressionMode.Compress, true))
{
buffer.CopyTo(compressor);
}
}
else
{
using (var compressor = new GZipStream(buffer, CompressionMode.Decompress))
{
compressor.CopyTo(targetStream);
}

}
break;
case CompressionMethod.None:
Expand All @@ -487,7 +510,7 @@ public static MemoryStream Compress(this Stream buffer, CompressionMethod method

return targetStream;
}

/// <summary>
/// Compresses/Decompresses the specified buffer using the compression algorithm.
/// </summary>
Expand Down
6 changes: 3 additions & 3 deletions test/Unosquare.Labs.EmbedIO.Tests/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
},
"dependencies": {
"dotnet-test-nunit": "3.4.0-beta-3",
"NUnit": "3.6.1",
"NUnit": "3.7.0",
"Unosquare.Labs.EmbedIO": { "target": "project" }
},

Expand All @@ -16,14 +16,14 @@
"netcoreapp1.1": {
"imports": "dnxcore50",
"dependencies": {
"Microsoft.NETCore.App": "1.1.1",
"Microsoft.NETCore.App": "1.1.2",
"System.Net.Http": "4.3.1"
}
},
"netcoreapp1.0": {
"imports": "dnxcore50",
"dependencies": {
"Microsoft.NETCore.App": "1.0.4",
"Microsoft.NETCore.App": "1.1.2",
"System.Net.Http": "4.3.1"
}
},
Expand Down

0 comments on commit 390dab3

Please sign in to comment.