本文整理汇总了C#中ICSharpCode.SharpZipLib.Zip.Compression.Streams.InflaterInputStream类的典型用法代码示例。如果您正苦于以下问题:C# InflaterInputStream类的具体用法?C# InflaterInputStream怎么用?C# InflaterInputStream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
InflaterInputStream类属于ICSharpCode.SharpZipLib.Zip.Compression.Streams命名空间,在下文中一共展示了InflaterInputStream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Decode
private Stream Decode()
{
Stream stream;
if (Encoding != "base64")
throw new Exception("TmxMapperPCL.Data: Only Base64-encoded data is supported.");
var rawData = Convert.FromBase64String(Value);
var memStream = new MemoryStream(rawData);
if (Compression == "gzip")
stream = new GZipInputStream(memStream);
else if (Compression == "zlib")
stream = new InflaterInputStream(memStream);
else if (Compression != null)
throw new Exception("TmxMapperPCL.Data: Unknown compression.");
else
stream = memStream;
var outputStream = new MemoryStream();
stream.CopyTo(outputStream);
stream = outputStream;
return stream;
}
示例2: CloseInflatorWithNestedUsing
public void CloseInflatorWithNestedUsing()
{
using (var store = IsolatedStorageFile.GetUserStoreForApplication())
{
string tempFile = Environment.TickCount.ToString();
store.CreateDirectory(tempFile);
tempFile = Path.Combine(tempFile, "SharpZipTest.Zip");
using (IsolatedStorageFileStream diskFile = store.CreateFile(tempFile))
using (DeflaterOutputStream deflator = new DeflaterOutputStream(diskFile))
using (StreamWriter textWriter = new StreamWriter(deflator))
{
textWriter.Write("Hello");
textWriter.Flush();
}
using (IsolatedStorageFileStream diskFile = store.OpenFile(tempFile, FileMode.Open))
using (InflaterInputStream deflator = new InflaterInputStream(diskFile))
using (StreamReader textReader = new StreamReader(deflator))
{
char[] buffer = new char[5];
int readCount = textReader.Read(buffer, 0, 5);
Assert.AreEqual(5, readCount);
StringBuilder b = new StringBuilder();
b.Append(buffer);
Assert.AreEqual("Hello", b.ToString());
}
store.CreateFile(tempFile);
}
}
示例3: Deserialize
public static void Deserialize(Stream stream, PiaFile piaFile)
{
if (stream == null)
throw new ArgumentNullException("Stream");
if (piaFile == null)
throw new ArgumentNullException("PiaFile");
try
{
// Header
var headerBytes = new Byte[48]; // Ignore 12 byte checksum
stream.Read(headerBytes, 0, headerBytes.Length);
var headerString = Encoding.Default.GetString(headerBytes);
piaFile.Header = new PiaHeader(headerString);
// Inflation
string inflatedString;
stream.Seek(60, SeekOrigin.Begin);
using (var zStream = new InflaterInputStream(stream))
{
var sr = new StreamReader(zStream, Encoding.Default);
inflatedString = sr.ReadToEnd();
}
// Nodes
piaFile.Owner = piaFile;
_deserializeNode(piaFile, inflatedString);
}
catch (Exception)
{
throw;
}
}
示例4: Decompress
public void Decompress(Stream source, Stream destination)
{
var inflater = new InflaterInputStream(source, new Inflater(true));
var dataBuffer = new byte[CopyBufferSize];
StreamUtils.Copy(inflater, destination, dataBuffer);
}
示例5: ExpandString
/// <summary>
/// Expands (de-compresses) a string.
/// </summary>
/// <param name="value">The string to expanded.</param>
/// <returns>The expanded string.</returns>
public string ExpandString(string value)
{
// The input value must be non-null
if (value == null)
{
throw new ArgumentNullException("value");
}
var outputData = string.Empty;
var inputData = Convert.FromBase64String(value);
using (var inputStream = new MemoryStream(inputData))
{
using (var outputStream = new MemoryStream())
{
// Zip the string
using (var zipStream = new InflaterInputStream(inputStream))
{
zipStream.IsStreamOwner = false;
StreamUtils.Copy(zipStream, outputStream, new byte[4096]);
}
// Convert to a string
outputData = UTF8Encoding.UTF8.GetString(outputStream.GetBuffer(), 0, Convert.ToInt32(outputStream.Length));
}
}
// Return the compressed string
return outputData;
}
示例6: Inflate
internal static byte[] Inflate(byte[] buffer)
{
InflaterInputStream inflaterStream = new InflaterInputStream(new MemoryStream(buffer));
MemoryStream outputStream = new MemoryStream();
inflaterStream.CopyTo(outputStream);
return outputStream.ToArray();
}
示例7: 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();
}
示例8: 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;
}
示例9: GetDimensions
public Rectangle GetDimensions(Stream stream)
{
Stream inputStream = null;
byte[] signature = new byte[8];
byte[] rect = new byte[8];
stream.Read(signature, 0, 8);
if ("CWS" == System.Text.Encoding.ASCII.GetString(signature, 0, 3))
{
inputStream = new InflaterInputStream(stream);
}
else
{
inputStream = stream;
}
inputStream.Read(rect, 0, 8);
int nbits = rect[0] >> 3;
rect[0] = (byte)(rect[0] & 0x07);
String bits = ByteArrayToBitString(rect);
bits = bits.Remove(0, 5);
int[] dims = new int[4];
for (int i = 0; i < 4; i++)
{
char[] dest = new char[nbits];
bits.CopyTo(0, dest, 0, bits.Length > nbits ? nbits : bits.Length);
bits = bits.Remove(0, bits.Length > nbits ? nbits : bits.Length);
dims[i] = BitStringToInteger(new String(dest)) / 20;
}
return new Rectangle(0, 0, dims[1] - dims[0], dims[3] - dims[2]);
}
示例10: CloseInflatorWithNestedUsing
public void CloseInflatorWithNestedUsing()
{
string tempFile = null;
try {
tempFile = Path.GetTempPath();
} catch (SecurityException) {
}
Assert.IsNotNull(tempFile, "No permission to execute this test?");
tempFile = Path.Combine(tempFile, "SharpZipTest.Zip");
using (FileStream diskFile = File.Create(tempFile))
using (DeflaterOutputStream deflator = new DeflaterOutputStream(diskFile))
using (StreamWriter textWriter = new StreamWriter(deflator)) {
textWriter.Write("Hello");
textWriter.Flush();
}
using (FileStream diskFile = File.OpenRead(tempFile))
using (InflaterInputStream deflator = new InflaterInputStream(diskFile))
using (StreamReader textReader = new StreamReader(deflator)) {
char[] buffer = new char[5];
int readCount = textReader.Read(buffer, 0, 5);
Assert.AreEqual(5, readCount);
var b = new StringBuilder();
b.Append(buffer);
Assert.AreEqual("Hello", b.ToString());
}
File.Delete(tempFile);
}
示例11: 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]);
}
}
示例12: 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);
}
}
}
}
示例13: 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;
}
示例14: 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!");
}
}
示例15: 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;
}