本文整理汇总了C#中DeflateStream.Close方法的典型用法代码示例。如果您正苦于以下问题:C# DeflateStream.Close方法的具体用法?C# DeflateStream.Close怎么用?C# DeflateStream.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DeflateStream
的用法示例。
在下文中一共展示了DeflateStream.Close方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DecompressProfile
static void DecompressProfile(string srcfile, string dstfile)
{
try
{
Console.WriteLine("Reading source...");
byte[] x = File.ReadAllBytes(srcfile); // load all bytes
byte[] y = new byte[x.Length-0x1A];
Console.WriteLine("Copying array...");
Array.Copy(x, 0x1A, y, 0, y.Length); // skip hash (0x14) + uncompresed size (0x4) + zlib compression type (0x2) = 0x1A
Console.WriteLine("Initializing streams...");
DeflateStream defStream = new DeflateStream(new MemoryStream(y),CompressionMode.Decompress);
FileStream fs = File.Create(dstfile);
Console.WriteLine("Decompressing data to destination...");
defStream.CopyTo(fs);
Console.WriteLine("Decompression done.\n" + dstfile);
defStream.Close();
fs.Close();
}
catch(Exception ex)
{
Console.WriteLine(ex.GetType().Name + " | " + ex.Message);
Console.Beep();
}
return;
}
示例2: Compress
// netz.compress.ICompress implementation
public long Compress(string file, string zipFile)
{
long length = -1;
FileStream ifs = null;
FileStream ofs = null;
try
{
ifs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read);
ofs = File.Open(zipFile, FileMode.Create, FileAccess.Write, FileShare.None);
DeflateStream dos = new DeflateStream(ofs, CompressionMode.Compress, true);
byte[] buff = new byte[ifs.Length];
while(true)
{
int r = ifs.Read(buff, 0, buff.Length);
if(r <= 0) break;
dos.Write(buff, 0, r);
}
dos.Flush();
dos.Close();
length = ofs.Length;
}
finally
{
if(ifs != null) ifs.Close();
if(ofs != null) ofs.Close();
}
return length;
}
示例3: Decompress
public static byte[] Decompress(byte[] data)
{
try
{
string result = string.Empty;
byte[] buffer = { };
MemoryStream ms = new MemoryStream(data);
Stream s = new DeflateStream(ms, CompressionMode.Decompress);
int len = 4096;
while (true)
{
int oldLen = buffer.Length;
Array.Resize(ref buffer, oldLen + len);
int size = s.Read(buffer, oldLen, len);
if (size != len)
{
Array.Resize(ref buffer, buffer.Length - (len - size));
break;
}
if (size <= 0)
break;
}
s.Close();
return buffer;
}
catch
{
return null;
}
}
示例4: CompressProfile
static void CompressProfile(string srcfile, string dstfile)
{
try
{
Console.WriteLine("Reading source...");
byte[] x = File.ReadAllBytes(srcfile);
int usize = x.Length;
Console.WriteLine("Initializing memory stream...");
MemoryStream ms = new MemoryStream();
// write uncompressed size as big endian
ms.WriteByte((byte)((usize>>24) & 0xFF));
ms.WriteByte((byte)((usize>>16) & 0xFF));
ms.WriteByte((byte)((usize>>8) & 0xFF));
ms.WriteByte((byte)(usize & 0xFF));
// then, compressed data
// these two bytes are part of zlib standard, but aren't supported by DeflateStream
ms.WriteByte(0x78);
ms.WriteByte(0x9C);
Console.WriteLine("Compressing data...");
MemoryStream compData = new MemoryStream();
DeflateStream ds = new DeflateStream(compData, CompressionMode.Compress);
ds.Write(x, 0, x.Length);
ds.Close();
ms.Write(compData.ToArray(), 0, compData.ToArray().Length);
// Adler32 checksum as big endian - also not supported by DeflateStream, but required by zlib standard
int checksum = GetAdler32(x);
ms.WriteByte((byte)((checksum>>24) & 0xFF));
ms.WriteByte((byte)((checksum>>16) & 0xFF));
ms.WriteByte((byte)((checksum>>8) & 0xFF));
ms.WriteByte((byte)(checksum & 0xFF));
// start filestream
Console.WriteLine("Creating file stream...");
FileStream fs = File.Create(dstfile);
// write hash
fs.Write(new SHA1CryptoServiceProvider().ComputeHash(ms.ToArray()), 0, 0x14);
// write usize + compressed data
fs.Write(ms.ToArray(), 0, ms.ToArray().Length);
Console.WriteLine("Compression done.\n" + dstfile);
fs.Close();
ms.Close();
compData.Close();
}
catch(Exception ex)
{
Console.WriteLine(ex.GetType().Name + " | " + ex.Message);
Console.Beep();
}
return;
}
示例5: Compress
public static byte[] Compress(byte[] data)
{
try
{
MemoryStream ms = new MemoryStream();
Stream s = new DeflateStream(ms, CompressionMode.Compress);
s.Write(data, 0, data.Length);
s.Close();
return ms.ToArray();
}
catch
{
return null;
}
}
示例6: FromXML
public override void FromXML(XmlNode node)
{
if (node != null && node.Name == "layer")
{
XmlAttributeCollection attrs = node.Attributes;
m_name = attrs["name"].Value;
m_layerDimensions.first = Convert.ToInt32(attrs["width"].Value);
m_layerDimensions.second = Convert.ToInt32(attrs["height"].Value);
foreach(XmlNode child in node.ChildNodes)
{
if (child.Name == "properties")
{
foreach (XmlNode propertyNode in child)
{
if (propertyNode.Name != "property")
continue;
XmlAttributeCollection propertyAtts = propertyNode.Attributes;
m_properties[propertyAtts["name"].Value] = propertyAtts["value"].Value;
}
}
else if (child.Name == "data")
{
m_data = new TileData();
attrs = child.Attributes;
if (attrs["encoding"]!= null)
{
string[] encodings = { "", "csv", "base64" };
string encodingValue = attrs["encoding"].Value;
int encodingIdx = Array.IndexOf(encodings, encodingValue);
if (encodingIdx >= 0)
{
m_data.m_encoding = (TileEncodingType)encodingIdx;
}
string[] compressions = { "", "gzip", "zlib" };
string compression = attrs["compression"].Value;
int compressionIdx = Array.IndexOf(compressions, compression);
if (compressionIdx >= 0)
{
m_data.m_compression = (TileCompressionType)compressionIdx;
}
switch(m_data.m_encoding)
{
case TileEncodingType.kCSV:
{
string text = child.InnerText;
string[] values = text.Split(',');
foreach (string v in values)
{
uint value = Convert.ToUInt32(v);
TileInfo info = new TileInfo();
info.m_horizontalFlip = (value & FLIPPED_HORIZONTALLY_FLAG) != 0;
info.m_verticalFlip = (value & FLIPPED_VERTICALLY_FLAG) != 0;
info.m_diagonalFlip = (value & FLIPPED_DIAGONALLY_FLAG) != 0;
value = value & ~(FLIPPED_DIAGONALLY_FLAG | FLIPPED_HORIZONTALLY_FLAG | FLIPPED_VERTICALLY_FLAG);
info.m_gid = value;
m_data.m_tiles.Add(info);
}
break;
}
case TileEncodingType.kBase64:
{
byte[] bytes = null;
switch(m_data.m_compression)
{
case TileCompressionType.kNone:
{
bytes = Convert.FromBase64String(child.InnerText);
break;
}
case TileCompressionType.kGzip:
{
//Transform string into byte[]
string str = child.InnerText;
byte[] byteArray = new byte[str.Length];
int indexBA = 0;
foreach (char item in str.ToCharArray())
{
byteArray[indexBA++] = (byte)item;
}
MemoryStream ms = new MemoryStream(byteArray);
GZipStream gzip = new GZipStream(ms, CompressionMode.Decompress);
byteArray = new byte[byteArray.Length];
int rBytes = gzip.Read(byteArray, 0, byteArray.Length);
StringBuilder sb = new StringBuilder(rBytes);
for (int i = 0; i < rBytes; ++i)
{
sb.Append((char)byteArray[i]);
}
gzip.Close();
ms.Close();
gzip.Dispose();
ms.Dispose();
bytes = Convert.FromBase64String(sb.ToString());
//.........这里部分代码省略.........
示例7: ReadPacket
void ReadPacket( byte opcode )
{
reader.Remove( 1 ); // remove opcode
lastOpcode = (PacketId)opcode;
switch( (PacketId)opcode ) {
case PacketId.Handshake:
{
byte protocolVer = reader.ReadUInt8();
ServerName = reader.ReadAsciiString();
ServerMotd = reader.ReadAsciiString();
game.LocalPlayer.SetUserType( reader.ReadUInt8() );
receivedFirstPosition = false;
game.LocalPlayer.ParseHackFlags( ServerName, ServerMotd );
} break;
case PacketId.Ping:
break;
case PacketId.LevelInitialise:
{
game.Map.Reset();
game.SetNewScreen( new LoadingMapScreen( game, ServerName, ServerMotd ) );
if( ServerMotd.Contains( "cfg=" ) ) {
ReadWomConfigurationAsync();
}
receivedFirstPosition = false;
gzipHeader = new GZipHeaderReader();
// Workaround because built in mono stream assumes that the end of stream
// has been reached the first time a read call returns 0. (MS.NET doesn't)
#if __MonoCS__
gzipStream = new DeflateStream( gzippedMap, true );
#else
gzipStream = new DeflateStream( gzippedMap, CompressionMode.Decompress );
if( OpenTK.Configuration.RunningOnMono ) {
Utils.LogWarning( "You are running on Mono, but this build does not support the Mono workaround." );
Utils.LogWarning( "You should either download the Mono compatible build or define '__MonoCS__' when targeting Mono. " +
"(The Mono compiler already defines this by default)" );
Utils.LogWarning( "You will likely experience an 'Internal error (no progress possible) ReadInternal' exception when decompressing the map." );
}
#endif
mapSizeIndex = 0;
mapIndex = 0;
receiveStart = DateTime.UtcNow;
} break;
case PacketId.LevelDataChunk:
{
int usedLength = reader.ReadInt16();
gzippedMap.Position = 0;
gzippedMap.SetLength( usedLength );
if( gzipHeader.done || gzipHeader.ReadHeader( gzippedMap ) ) {
if( mapSizeIndex < 4 ) {
mapSizeIndex += gzipStream.Read( mapSize, mapSizeIndex, 4 - mapSizeIndex );
}
if( mapSizeIndex == 4 ) {
if( map == null ) {
int size = mapSize[0] << 24 | mapSize[1] << 16 | mapSize[2] << 8 | mapSize[3];
map = new byte[size];
}
mapIndex += gzipStream.Read( map, mapIndex, map.Length - mapIndex );
}
}
reader.Remove( 1024 );
byte progress = reader.ReadUInt8();
game.Events.RaiseMapLoading( progress );
} break;
case PacketId.LevelFinalise:
{
game.SetNewScreen( new NormalScreen( game ) );
int mapWidth = reader.ReadInt16();
int mapHeight = reader.ReadInt16();
int mapLength = reader.ReadInt16();
double loadingMs = ( DateTime.UtcNow - receiveStart ).TotalMilliseconds;
Utils.LogDebug( "map loading took:" + loadingMs );
game.Map.UseRawMap( map, mapWidth, mapHeight, mapLength );
game.Events.RaiseOnNewMapLoaded();
map = null;
gzipStream.Close();
if( sendWomId && !sentWomId ) {
SendChat( "/womid WoMClient-2.0.7" );
sentWomId = true;
}
gzipStream = null;
GC.Collect( 0 );
} break;
case PacketId.SetBlock:
{
int x = reader.ReadInt16();
int y = reader.ReadInt16();
int z = reader.ReadInt16();
byte type = reader.ReadUInt8();
if( !game.Map.IsNotLoaded )
game.UpdateBlock( x, y, z, type );
else
//.........这里部分代码省略.........
示例8: DecompressDisplay
/// <summary>
/// Decompress and display the update contents
/// </summary>
/// <param name="data">data bytes</param>
private void DecompressDisplay(byte[] data)
{
var compressedStream = new MemoryStream(data);
Int32 x, y, w, h;
using (MemoryStream clearStream = new MemoryStream()) {
using (DeflateStream zipStream = new DeflateStream(compressedStream, CompressionMode.Decompress)) {
byte[] buffer = new byte[4096];
byte[] szBuf = new byte[4];
int readAmt;
readAmt = zipStream.Read(szBuf, 0, 4);
Debug.Assert(readAmt == 4);
UInt32 hdr = System.BitConverter.ToUInt32(szBuf, 0);
hdr = (UInt32)System.Net.IPAddress.NetworkToHostOrder((Int32)hdr);
width = (Int32)(hdr >> 16);
height = (Int32)(hdr & 0xFFFF);
readAmt = zipStream.Read(szBuf, 0, 4);
Debug.Assert(readAmt == 4);
hdr = System.BitConverter.ToUInt32(szBuf, 0);
hdr = (UInt32)System.Net.IPAddress.NetworkToHostOrder((Int32)hdr);
maskX = (Int32)(hdr >> 16);
maskY = (Int32)(hdr & 0xFFFF);
readAmt = zipStream.Read(szBuf, 0, 4);
Debug.Assert(readAmt == 4);
hdr = System.BitConverter.ToUInt32(szBuf, 0);
hdr = (UInt32)System.Net.IPAddress.NetworkToHostOrder((Int32)hdr);
maskWidth = (Int32)(hdr >> 16);
maskHeight = (Int32)(hdr & 0xFFFF);
if (!((prevMX == maskX) && (prevMY == maskY) && (prevMW == maskWidth) && (prevMH == maskHeight))) {
DisplayMask(maskX, maskY, maskWidth, maskHeight, width, height);
prevMX = maskX;
prevMY = maskY;
prevMW = maskWidth;
prevMH = maskHeight;
}
readAmt = zipStream.Read(szBuf, 0, 4);
Debug.Assert(readAmt == 4);
hdr = System.BitConverter.ToUInt32(szBuf, 0);
hdr = (UInt32)System.Net.IPAddress.NetworkToHostOrder((Int32)hdr);
x = (Int32)(hdr >> 16);
y = (Int32)(hdr & 0xFFFF);
readAmt = zipStream.Read(szBuf, 0, 4);
Debug.Assert(readAmt == 4);
hdr = System.BitConverter.ToUInt32(szBuf, 0);
hdr = (UInt32)System.Net.IPAddress.NetworkToHostOrder((Int32)hdr);
w = (Int32)(hdr >> 16);
h = (Int32)(hdr & 0xFFFF);
int read = 0;
while (true) {
try {
read = zipStream.Read(buffer, 0, buffer.Length);
} catch (Exception e) {
// Trace.WriteLine("{0} Error code: {}.", e.Message, e.ErrorCode);
MessageBox.Show("Message: " + e.Message, "FATAL");
}
if (read > 0)
clearStream.Write(buffer, 0, read);
else
break;
}
zipStream.Close();
}
DisplayUpdate(x, y, w, h, clearStream.ToArray());
}
}
示例9: Zlib_DisposedException_DeflateStream
public void Zlib_DisposedException_DeflateStream()
{
string TextToCompress = LetMeDoItNow;
MemoryStream ms1= new MemoryStream();
Stream compressor= new DeflateStream(ms1, CompressionMode.Compress, false);
TestContext.WriteLine("Text to compress is {0} bytes: '{1}'",
TextToCompress.Length, TextToCompress);
TestContext.WriteLine("using compressor: {0}", compressor.GetType().FullName);
StreamWriter sw = new StreamWriter(compressor, System.Text.Encoding.ASCII);
sw.Write(TextToCompress);
sw.Close(); // implicitly closes compressor
sw.Close(); // implicitly closes compressor, again
compressor.Close(); // explicitly closes compressor
var a = ms1.ToArray();
TestContext.WriteLine("Compressed stream is {0} bytes long", a.Length);
var ms2 = new MemoryStream(a);
Stream decompressor = new DeflateStream(ms2, CompressionMode.Decompress, false);
TestContext.WriteLine("using decompressor: {0}", decompressor.GetType().FullName);
var sr = new StreamReader(decompressor, System.Text.Encoding.ASCII);
string DecompressedText = sr.ReadToEnd();
sr.Close();
TestContext.WriteLine("decompressor.CanRead = {0}",decompressor.CanRead);
TestContext.WriteLine("Read {0} characters: '{1}'", DecompressedText.Length, DecompressedText);
TestContext.WriteLine("\n");
Assert.AreEqual<String>(TextToCompress, DecompressedText);
}
示例10: DeflateCompressDecompress
public static void DeflateCompressDecompress(string filename)
{
Console.WriteLine("Test compression and decompression on file {0}", filename);
FileStream infile;
try
{
// Open the file as a FileStream object.
infile = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read);
byte[] buffer = new byte[infile.Length];
// Read the file to ensure it is readable.
int count = infile.Read(buffer, 0, buffer.Length);
if (count != buffer.Length)
{
infile.Close();
Console.WriteLine("Test Failed: Unable to read data from file");
return;
}
infile.Close();
MemoryStream ms = new MemoryStream();
// Use the newly created memory stream for the compressed data.
DeflateStream compressedzipStream = new DeflateStream(ms, CompressionMode.Compress, true);
Console.WriteLine("Compression");
compressedzipStream.Write(buffer, 0, buffer.Length);
// Close the stream.
compressedzipStream.Close();
Console.WriteLine("Original size: {0}, Compressed size: {1}", buffer.Length, ms.Length);
// Reset the memory stream position to begin decompression.
ms.Position = 0;
DeflateStream zipStream = new DeflateStream(ms, CompressionMode.Decompress);
Console.WriteLine("Decompression");
byte[] decompressedBuffer = new byte[buffer.Length + 100];
// Use the ReadAllBytesFromStream to read the stream.
int totalCount = DeflateTest.ReadAllBytesFromStream(zipStream, decompressedBuffer);
Console.WriteLine("Decompressed {0} bytes", totalCount);
if (!DeflateTest.CompareData(buffer, buffer.Length, decompressedBuffer, totalCount))
{
Console.WriteLine("Error. The two buffers did not compare.");
}
zipStream.Close();
} // end try
catch (InvalidDataException)
{
Console.WriteLine("Error: The file being read contains invalid data.");
}
catch (FileNotFoundException)
{
Console.WriteLine("Error:The file specified was not found.");
}
catch (ArgumentException)
{
Console.WriteLine("Error: path is a zero-length string, contains only white space, or contains one or more invalid characters");
}
catch (PathTooLongException)
{
Console.WriteLine("Error: The specified path, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters.");
}
catch (DirectoryNotFoundException)
{
Console.WriteLine("Error: The specified path is invalid, such as being on an unmapped drive.");
}
catch (IOException)
{
Console.WriteLine("Error: An I/O error occurred while opening the file.");
}
catch (UnauthorizedAccessException)
{
Console.WriteLine("Error: path specified a file that is read-only, the path is a directory, or caller does not have the required permissions.");
}
catch (IndexOutOfRangeException)
{
Console.WriteLine("Error: You must provide parameters for MyGZIP.");
}
}
示例11: ResponseData
public const ResponseDataType DefaultDataType = ResponseDataType.PlainText; //PlainText ZipBinary ZipBase64
#endregion Fields
#region Methods
/// <summary>
/// 将报表XML数据文本输出到HTTP请求
/// </summary>
/// <param name="DataPage"></param>
/// <param name="DataText"></param>
/// <param name="DataType"></param>
public static void ResponseData(System.Web.UI.Page DataPage, ref string DataText, ResponseDataType DataType)
{
//报表XML数据的前后不能附加任何其它数据,否则XML数据将不能成功解析,所以调用ClearContent方法清理网页中前面多余的数据
DataPage.Response.ClearContent();
if (ResponseDataType.PlainText == DataType)
{
// 把xml对象发送给客户端
//DataPage.Response.ContentType = "text/xml";
DataPage.Response.Write(DataText);
}
else
{
//将string数据转换为byte[],以便进行压缩
System.Text.UTF8Encoding converter = new System.Text.UTF8Encoding();
byte[] XmlBytes = converter.GetBytes(DataText);
//在 HTTP 头信息中写入报表数据压缩信息
DataPage.Response.AppendHeader("gr_zip_type", "deflate"); //指定压缩方法
DataPage.Response.AppendHeader("gr_zip_size", XmlBytes.Length.ToString()); //指定数据的原始长度
DataPage.Response.AppendHeader("gr_zip_encode", converter.HeaderName); //指定数据的编码方式 utf-8 utf-16 ...
// 把压缩后的xml数据发送给客户端
if (ResponseDataType.ZipBinary == DataType)
{
System.IO.Compression.DeflateStream compressedzipStream = new DeflateStream(DataPage.Response.OutputStream, CompressionMode.Compress, true);
compressedzipStream.Write(XmlBytes, 0, XmlBytes.Length);
compressedzipStream.Close();
}
else //ResponseDataType.ZipBase64
{
MemoryStream memStream = new MemoryStream();
DeflateStream compressedzipStream = new DeflateStream(memStream, CompressionMode.Compress, true);
compressedzipStream.Write(XmlBytes, 0, XmlBytes.Length);
compressedzipStream.Close(); //这句很重要,这样数据才能全部写入 MemoryStream
// Read bytes from the stream.
memStream.Seek(0, SeekOrigin.Begin); // Set the position to the beginning of the stream.
int count = (int)memStream.Length;
byte[] byteArray = new byte[count];
count = memStream.Read(byteArray, 0, count);
string Base64Text = Convert.ToBase64String(byteArray);
DataPage.Response.Write(Base64Text);
}
}
//报表XML数据的前后不能附加任何其它数据,否则XML数据将不能成功解析,所以调用End方法放弃网页中后面不必要的数据
DataPage.Response.End();
}
示例12: writeMesh
private static void writeMesh(Mesh m) {
string filepath = folderName + "/" + m.name + ".mesh";
if (File.Exists(filepath)) {
File.Delete(filepath);
}
MemoryStream ms = new MemoryStream();
BinaryWriter bw = new BinaryWriter(ms);
Debug.Log("Write Mesh:" + m.name + " to disk:" + filepath);
// write length
bw.Write(m.name.Length);
// write name
bw.Write(m.name.ToCharArray());
// write matrix
float[] rawData = new float[]{
1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0
};
for (int i = 0; i < rawData.Length; i++) {
bw.Write(rawData[i]);
}
// write sub mesh count
bw.Write(1);
// write vertex count
bw.Write(m.vertices.Length);
Debug.Log("\tVertices:" + m.vertices.Length);
foreach (Vector3 vert in m.vertices) {
bw.Write(vert.x);
bw.Write(vert.y);
bw.Write(vert.z);
}
// write uv0
bw.Write(m.uv.Length);
Debug.Log("\tUV0:" + m.uv.Length);
foreach (Vector2 uv0 in m.uv) {
bw.Write(uv0.x);
bw.Write(1 - uv0.y);
}
// write uv1
bw.Write(m.uv2.Length);
Debug.Log("\tUV1:" + m.uv2.Length);
foreach (Vector2 uv1 in m.uv2) {
bw.Write(uv1.x);
bw.Write(uv1.y);
}
Debug.Log("normals:" + m.normals.Length);
// write normal
if (normal) {
bw.Write(m.normals.Length);
foreach (Vector3 n in m.normals) {
bw.Write(n.x);
bw.Write(n.y);
bw.Write(n.z);
}
} else {
bw.Write(0);
}
Debug.Log("tangent:" + m.tangents.Length);
// write tangent
if (tangent) {
bw.Write(m.tangents.Length);
foreach (Vector3 t in m.tangents) {
bw.Write(t.x);
bw.Write(t.y);
bw.Write(t.z);
}
} else {
bw.Write(0);
}
// skeleton weights
bw.Write(0);
// skeleton indices
bw.Write(0);
// write indices
bw.Write(m.triangles.Length);
for (int i = 0; i < m.triangles.Length; i++) {
bw.Write(m.triangles[i]);
}
// bounds
bw.Write(m.bounds.min.x);
bw.Write(m.bounds.min.y);
bw.Write(m.bounds.min.z);
bw.Write(m.bounds.max.x);
bw.Write(m.bounds.max.y);
bw.Write(m.bounds.max.z);
bw.Close();
int size = ms.GetBuffer().Length;
MemoryStream compressionBytes = new MemoryStream();
// write to disk
DeflateStream compressionStream = new DeflateStream(compressionBytes, CompressionMode.Compress);
compressionStream.Write(ms.GetBuffer(), 0, ms.GetBuffer().Length);
compressionStream.Close();
FileStream fs = new FileStream(filepath, FileMode.Create);
BinaryWriter cbw = new BinaryWriter(fs);
// write compression type
cbw.Write(3);
// write original size
cbw.Write(size);
//.........这里部分代码省略.........
示例13: Decompress
private static byte[] Decompress(byte[] data)
{
MemoryStream stream = new MemoryStream(data, 4, data.Length - 4, false);
DeflateStream stream2 = new DeflateStream(stream, CompressionMode.Decompress);
byte[] buffer = new byte[(BitConverter.ToInt32(data, 0) - 1) + 1];
stream2.Read(buffer, 0, buffer.Length);
stream2.Close();
return buffer;
}