- tcp_client_server.zip
- TCP_client_server
- NET
- build.bat
- FileSystemClient
- FileSystemServer
- ICSharpCode.SharpZipLib.dll
- PluginInManager
- RemoteDesktopClient
- RemoteDesktopServer
- TCP_WIN_APP.sln
- TCPClient
- TCPClientCmd
- TCPClientWin
- TCPServer
- NETCF
- tcpwin_client.zip
- TCPWin_Client
- ICSharpCode.SharpZipLib.dll
- Interop.Shell32.dll
- Log
- PluginInMannager.dll
- plugins
- FileSystemClient.dll
- RemoteDesktopClient.dll
- TCPClient.dll
- TCPClientWin.exe
- tcpcf_server.zip
- TCPCF_Server
- ICSharpCode.SharpZipLib.dll
- PlugInManager.dll
- plugins
- FileSystemServer.dll
- RemoteDesktopServer.dll
- TCPServer.exe
- tcpwin_server.zip
- TCPWin_Server
- ICSharpCode.SharpZipLib.dll
- PluginInMannager.dll
- plugins
- FileSystemServer.dll
- SimpleRemoteDesktopServer.dll
- TCPServer.exe
- tcpwin_clientcmd.zip
- TCPWin_ClientCMD
- ICSharpCode.SharpZipLib.dll
- PluginInMannager.dll
- plugins
- FileSystemClient.dll
- RemoteDesktopClient.dll
- TCPClient.dll
- TCPClientCmd.exe
|
using System;
using System.IO;
using System.Text;
using ICSharpCode.SharpZipLib;
namespace SimpleICSharp
{
public enum CompressionType
{
GZip,
BZip2,
Zip
}
public class Compression
{
private static CompressionType compressionProvider = CompressionType.GZip;
private static int compressionLevel = 4;
private static Stream OutputStream(Stream inputStream)
{
switch (compressionProvider)
{
case CompressionType.BZip2:
return new ICSharpCode.SharpZipLib.BZip2.BZip2OutputStream(inputStream);
case CompressionType.Zip:
{
ICSharpCode.SharpZipLib.Zip.ZipOutputStream outStream = new ICSharpCode.SharpZipLib.Zip.ZipOutputStream(inputStream);
outStream.SetLevel(compressionLevel);
return outStream;
}
default:
{
ICSharpCode.SharpZipLib.GZip.GZipOutputStream outStream = new ICSharpCode.SharpZipLib.GZip.GZipOutputStream(inputStream);
outStream.SetLevel(compressionLevel);
return outStream;
}
}
}
private static Stream InputStream(Stream inputStream)
{
switch (compressionProvider)
{
case CompressionType.BZip2: return new ICSharpCode.SharpZipLib.BZip2.BZip2InputStream(inputStream);
case CompressionType.Zip: return new ICSharpCode.SharpZipLib.Zip.ZipInputStream(inputStream);
default: return new ICSharpCode.SharpZipLib.GZip.GZipInputStream(inputStream);
}
}
public static byte[] Compress(byte[] bytesToCompress)
{
MemoryStream ms = new MemoryStream();
Stream s = OutputStream(ms);
s.Write(bytesToCompress, 0, bytesToCompress.Length);
s.Close();
return ms.ToArray();
}
public static string Compress(string stringToCompress)
{
byte[] compressedData = CompressToByte(stringToCompress);
string strOut = Convert.ToBase64String(compressedData);
return strOut;
}
public static byte[] CompressToByte(string stringToCompress)
{
byte[] bytData = Encoding.Unicode.GetBytes(stringToCompress);
return Compress(bytData);
}
public static string DeCompress(string stringToDecompress)
{
string outString = string.Empty;
if (stringToDecompress == null)
throw new ArgumentNullException("stringToDecompress", "You tried to use an empty string");
byte[] inArr = Convert.FromBase64String(stringToDecompress.Trim());
byte[] outArr = DeCompress(inArr);
return System.Text.Encoding.Unicode.GetString(outArr, 0, outArr.Length);
}
public static byte[] DeCompress(byte[] bytesToDecompress)
{
byte[] writeData = new byte[4096];
Stream s2 = InputStream(new MemoryStream(bytesToDecompress));
MemoryStream outStream = new MemoryStream();
while (true)
{
int size = s2.Read(writeData, 0, writeData.Length);
if (size > 0)
outStream.Write(writeData, 0, size);
else
break;
}
s2.Close();
byte[] outArr = outStream.ToArray();
outStream.Close();
return outArr;
}
}
}
|
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.
I am a software developer in one of the largest retailer in our country. My job is (beside else) also in setting some standards in SW development throughout our company.
I have a M.Sc. in computer science and 20 years of experience. I have written 2 books in Slovenian language and both are sold out (the first about C++ language and the second about VBA language)...