Skip to content
This repository has been archived by the owner on Dec 13, 2018. It is now read-only.

Commit

Permalink
#28 - Use a GZipStream constructor that's supported on Mono.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tratcher committed Jul 25, 2014
1 parent 8b0500d commit c733aa8
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,25 @@ namespace Microsoft.AspNet.Security.DataHandler.Serializer
{
public class TicketSerializer : IDataSerializer<AuthenticationTicket>
{
private static readonly bool IsMono = Type.GetType("Mono.Runtime") != null;
private const int FormatVersion = 2;

[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2202:Do not dispose objects multiple times", Justification = "Dispose is idempotent")]
public virtual byte[] Serialize(AuthenticationTicket model)
{
using (var memory = new MemoryStream())
{
using (var compression = new GZipStream(memory, CompressionLevel.Optimal))
GZipStream compression;
if (IsMono)
{
// The other constructor is not currently supported on Mono.
compression = new GZipStream(memory, CompressionMode.Compress);
}
else
{
compression = new GZipStream(memory, CompressionLevel.Optimal);
}
using (compression)
{
using (var writer = new BinaryWriter(compression))
{
Expand Down

1 comment on commit c733aa8

@borgdylan
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have filed a mono bug so that they implement the CompressionLevel variants of the DeflateStream/GzipStream constructors.

Please sign in to comment.