本文整理汇总了C#中ICSharpCode.SharpZipLib.Zip.Compression.Streams.InflaterInputStream.Read方法的典型用法代码示例。如果您正苦于以下问题:C# InflaterInputStream.Read方法的具体用法?C# InflaterInputStream.Read怎么用?C# InflaterInputStream.Read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICSharpCode.SharpZipLib.Zip.Compression.Streams.InflaterInputStream
的用法示例。
在下文中一共展示了InflaterInputStream.Read方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestInflateDeflate
public void TestInflateDeflate()
{
MemoryStream ms = new MemoryStream();
Deflater deflater = new Deflater(6);
DeflaterOutputStream outStream = new DeflaterOutputStream(ms, deflater);
byte[] buf = new byte[1000000];
System.Random rnd = new Random();
rnd.NextBytes(buf);
outStream.Write(buf, 0, buf.Length);
outStream.Flush();
outStream.Finish();
ms.Seek(0, SeekOrigin.Begin);
InflaterInputStream inStream = new InflaterInputStream(ms);
byte[] buf2 = new byte[buf.Length];
int pos = 0;
while (true) {
int numRead = inStream.Read(buf2, pos, 4096);
if (numRead <= 0) {
break;
}
pos += numRead;
}
for (int i = 0; i < buf.Length; ++i) {
Assertion.AssertEquals(buf2[i], buf[i]);
}
}
示例2: DeCompress
/// <summary>
/// Decompresses an array of bytes.
/// </summary>
/// <param name="_pBytes">An array of bytes to be decompressed.</param>
/// <returns>Decompressed bytes</returns>
public static byte[] DeCompress(byte[] _pBytes)
{
InflaterInputStream inputStream = new InflaterInputStream(new MemoryStream(_pBytes));
MemoryStream ms = new MemoryStream();
Int32 mSize;
byte[] mWriteData = new byte[4096];
while (true)
{
mSize = inputStream.Read(mWriteData, 0, mWriteData.Length);
if (mSize > 0)
{
ms.Write(mWriteData, 0, mSize);
}
else
{
break;
}
}
inputStream.Close();
return ms.ToArray();
}
示例3: Decompress
public string Decompress(string compressedString)
{
var uncompressedString = string.Empty;
var totalLength = 0;
var inputAsBytes = Convert.FromBase64String(compressedString);;
var writeData = new byte[4096];
var inputStream = new InflaterInputStream(new MemoryStream(inputAsBytes));
for(;;)
{
var size = inputStream.Read(writeData, 0, writeData.Length);
if (size > 0)
{
totalLength += size;
uncompressedString += Encoding.UTF8.GetString(writeData, 0, size);
}
else
{
break;
}
}
inputStream.Close();
return uncompressedString;
}
示例4: Inflate
void Inflate(MemoryStream ms, byte[] original, int level, bool zlib)
{
ms.Seek(0, SeekOrigin.Begin);
Inflater inflater = new Inflater(!zlib);
InflaterInputStream inStream = new InflaterInputStream(ms, inflater);
byte[] buf2 = new byte[original.Length];
int currentIndex = 0;
int count = buf2.Length;
try
{
while (true)
{
int numRead = inStream.Read(buf2, currentIndex, count);
if (numRead <= 0)
{
break;
}
currentIndex += numRead;
count -= numRead;
}
}
catch(Exception ex)
{
Console.WriteLine("Unexpected exception - '{0}'", ex.Message);
throw;
}
if ( currentIndex != original.Length )
{
Console.WriteLine("Original {0}, new {1}", original.Length, currentIndex);
Assert.Fail("Lengths different");
}
for (int i = 0; i < original.Length; ++i)
{
if ( buf2[i] != original[i] )
{
string description = string.Format("Difference at {0} level {1} zlib {2} ", i, level, zlib);
if ( original.Length < 2048 )
{
StringBuilder builder = new StringBuilder(description);
for (int d = 0; d < original.Length; ++d)
{
builder.AppendFormat("{0} ", original[d]);
}
Assert.Fail(builder.ToString());
}
else
{
Assert.Fail(description);
}
}
}
}
示例5: Decompress
public void Decompress(ArraySegment<byte> input, ArraySegment<byte> output)
{
using (var gz = new InflaterInputStream(new MemoryStream(input.Array, input.Offset, input.Count)))
{
int read = gz.Read(output.Array, output.Offset, output.Count);
if (read != output.Count)
throw new Exception("Short read!");
}
}
示例6: Decompress
public static byte[] Decompress(byte[] data, int final_size)
{
byte[] r = null;
using (Stream s = new InflaterInputStream(new MemoryStream(data)))
s.Read(r, 0, final_size);
return r;
}
示例7: UncompressStream
public static byte[] UncompressStream(Stream stream, int filesize, int memsize)
{
BinaryReader r = new BinaryReader(stream);
long end = stream.Position + filesize;
byte[] header = r.ReadBytes(2);
if (checking) if (header.Length != 2)
throw new InvalidDataException("Hit unexpected end of file at " + stream.Position);
bool useDEFLATE = true;
byte[] uncompressedData = null;
if (header[0] == 0x78)
{
useDEFLATE = true;
}
else if (header[1] == 0xFB)
{
useDEFLATE = false;
}
else
{
throw new InvalidDataException("Unrecognized compression format");
}
if (useDEFLATE)
{
byte[] data = new byte[filesize];
stream.Position -= 2; // go back to header
stream.Read(data, 0, filesize);
using (MemoryStream source = new MemoryStream(data))
{
using (InflaterInputStream decomp = new InflaterInputStream(source))
{
uncompressedData = new byte[memsize];
decomp.Read(uncompressedData, 0, memsize);
}
}
}
else
{
uncompressedData = OldDecompress(stream, header[0]);
}
long realsize = uncompressedData.Length;
if (checking) if (realsize != memsize)
throw new InvalidDataException(String.Format(
"Resource data indicates size does not match index at 0x{0}. Read 0x{1}. Expected 0x{2}.",
stream.Position.ToString("X8"), realsize.ToString("X8"), memsize.ToString("X8")));
return uncompressedData;
}
示例8: Decode
public byte[] Decode(byte[] input, int decompressedSize)
{
InflaterInputStream stream = new InflaterInputStream(new MemoryStream(input));
byte[] data = new byte[4096];
MemoryStream outStream = new MemoryStream();
int size;
while ((size = stream.Read(data, 0, data.Length)) > 0)
{
outStream.Write(data, 0, size);
}
outStream.Capacity = (int)outStream.Length;
return outStream.GetBuffer();
}
示例9: Decompress
// Length = decompressed length
public static byte[] Decompress(int Length, byte[] Data)
{
byte[] Output = new byte[Length];
Stream s = new InflaterInputStream(new MemoryStream(Data));
int Offset = 0;
while(true)
{
int size = s.Read(Output, Offset, Length);
if (size == Length) break;
Offset += size;
Length -= size;
}
return Output;
}
示例10: Decompress
public static byte[] Decompress(string data)
{
byte[] array = null;
if (data.StartsWith("ZipStream:"))
{
MemoryStream memoryStream = new MemoryStream(Convert.FromBase64String(data.Substring(10)));
InflaterInputStream inflaterInputStream = new InflaterInputStream(memoryStream);
BinaryReader binaryReader = new BinaryReader(memoryStream);
int num = binaryReader.ReadInt32();
array = new byte[num];
inflaterInputStream.Read(array, 0, num);
inflaterInputStream.Close();
memoryStream.Close();
}
return array;
}
示例11: Decompress
public static void Decompress(ref GenericReader gr)
{
int uncompressedLength = gr.ReadInt32();
byte[] output = new byte[gr.ReadInt32()];
byte[] temp = gr.ReadBytes((int)gr.Remaining);
gr.Close();
Stream s = new InflaterInputStream(new MemoryStream(temp));
int offset = 0;
while (true)
{
int size = s.Read(output, offset, uncompressedLength);
if (size == uncompressedLength) break;
offset += size;
uncompressedLength -= size;
}
gr = new GenericReader(new MemoryStream(output));
//gr.BaseStream.Position = 0;
}
示例12: Inflate
public string Inflate(byte[] gzBuffer)
{
using (var ms = new MemoryStream())
{
var msgLength = BitConverter.ToInt32(gzBuffer, 0);
ms.Write(gzBuffer, 4, gzBuffer.Length - 4);
var buffer = new byte[msgLength];
ms.Position = 0;
using (var zipStream = new InflaterInputStream(ms, new Inflater()))
{
zipStream.Read(buffer, 0, buffer.Length);
}
return Encoding.UTF8.GetString(buffer);
}
}
示例13: Decompress
public byte[] Decompress( byte[] bytes )
{
Stream stream = new InflaterInputStream( new MemoryStream( bytes ) );
MemoryStream memory = new MemoryStream();
int totalLength = 0;
byte[] writeData = new byte[4096];
while ( true )
{
int size = stream.Read( writeData, 0, writeData.Length );
if ( size > 0 )
{
totalLength += size;
memory.Write( writeData, 0, size );
}
else
break;
}
stream.Close();
return memory.ToArray();
}
示例14: Decompress
public static byte[] Decompress(byte[] bytes)
{
InflaterInputStream stream = new InflaterInputStream(new MemoryStream(bytes));
MemoryStream memory = new MemoryStream();
Byte[] writeData = new byte[4096];
int size;
while (true)
{
size = stream.Read(writeData, 0, writeData.Length);
if (size > 0)
{
memory.Write(writeData, 0, size);
}
else
{
break;
}
}
stream.Close();
return memory.ToArray();
}
示例15: ProcessData
public static MemoryStream ProcessData(byte[] data)
{
if (data == null)
{
return null;
}
MemoryStream baseInputStream = null;
MemoryStream stream2;
InflaterInputStream stream3 = null;
try
{
baseInputStream = new MemoryStream(data);
stream2 = new MemoryStream();
stream3 = new InflaterInputStream(baseInputStream);
byte[] buffer = new byte[data.Length];
while (true)
{
int count = stream3.Read(buffer, 0, buffer.Length);
if (count <= 0)
{
break;
}
stream2.Write(buffer, 0, count);
}
stream2.Flush();
stream2.Seek(0L, SeekOrigin.Begin);
}
finally
{
if (baseInputStream != null)
{
baseInputStream.Close();
}
if (stream3 != null)
{
stream3.Close();
}
}
return stream2;
}