- infocenter.zip
- InfoCenter
- ConfigSamples
- InfoCenter.Agent
- InfoCenter.Logic.Tests
- InfoCenter.Logic
- Agent
- Entities
- Helpers
- bin
- Debug
- Antlr3.Runtime.dll
- hibernate.cfg.xml
- Iesi.Collections.dll
- InfoCenter.Logic.dll
- InfoCenter.Logic.dll.mdb
- InfoCenter.Logic.pdb
- InfoCenter.Persistence.dll
- InfoCenter.Persistence.dll.mdb
- InfoCenter.Persistence.pdb
- log4net.dll
- Release
- InfoCenter.Logic.csproj
- InfoCenter.Logic.pidb
- obj
- Debug
- PacketParser.cs
- Properties
- InfoCenter.Persistence.Test
- InfoCenter.Persistence
- InfoCenter.sln
- InfoCenter.userprefs
- InfoCenter.WebConsole
- SharedLibs
- Antlr3.Runtime.dll
- Castle.Core.dll
- Castle.DynamicProxy2.dll
- Iesi.Collections.dll
- log4net.dll
- MySql.Data.dll
- NHibernate.ByteCode.Castle.dll
- NHibernate.dll
- nunit.framework.dll
- test-results
|
using System;
using System.Text;
using System.IO;
using System.IO.Compression;
namespace InfoCenter.Agent.Helpers
{
public static class Archiver
{
public static string Compress(string text)
{
byte[] buffer = Encoding.UTF8.GetBytes(text);
MemoryStream ms = new MemoryStream();
using (GZipStream zip = new GZipStream(ms, CompressionMode.Compress, true))
{
zip.Write(buffer, 0, buffer.Length);
}
ms.Position = 0;
byte[] compressed = new byte[ms.Length];
ms.Read(compressed, 0, compressed.Length);
byte[] gzBuffer = new byte[compressed.Length + 4];
Buffer.BlockCopy(compressed, 0, gzBuffer, 4, compressed.Length);
Buffer.BlockCopy(BitConverter.GetBytes(buffer.Length), 0, gzBuffer, 0, 4);
return Convert.ToBase64String(gzBuffer);
}
public static string Decompress(string compressedText)
{
byte[] gzBuffer = Convert.FromBase64String(compressedText);
using (MemoryStream ms = new MemoryStream())
{
int msgLength = BitConverter.ToInt32(gzBuffer, 0);
ms.Write(gzBuffer, 4, gzBuffer.Length - 4);
byte[] buffer = new byte[msgLength];
ms.Position = 0;
using (GZipStream zip = new GZipStream(ms, CompressionMode.Decompress))
{
zip.Read(buffer, 0, buffer.Length);
}
return Encoding.UTF8.GetString(buffer);
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Interested in design/development of framework functionality using the best patterns and practices.