本文整理汇总了C#中ICSharpCode.SharpZipLib.GZip.GZipInputStream类的典型用法代码示例。如果您正苦于以下问题:C# GZipInputStream类的具体用法?C# GZipInputStream怎么用?C# GZipInputStream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
GZipInputStream类属于ICSharpCode.SharpZipLib.GZip命名空间,在下文中一共展示了GZipInputStream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Decompress
public byte[] Decompress(byte[] data)
{
using (MemoryStream inputStream = new MemoryStream())
{
inputStream.Write(data, 0, data.Length);
inputStream.Position = 0;
using (Stream decompressStream = new GZipInputStream(inputStream))
{
using (MemoryStream outputStream = new MemoryStream())
{
byte[] buffer = new byte[BUFFER_SIZE];
while (true)
{
int size = decompressStream.Read(buffer, 0, buffer.Length);
if (size > 0)
{
outputStream.Write(buffer, 0, size);
}
else
{
break;
}
}
decompressStream.Close();
return outputStream.ToArray();
}
}
}
}
示例2: 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;
}
示例3: GZip_Compress_Extract_Test
public void GZip_Compress_Extract_Test() {
var plainStream = PlainText.ToStream();
plainStream.Seek(0, SeekOrigin.Begin);
var plainData = Encoding.UTF8.GetBytes(PlainText);
byte[] compressedData;
byte[] extractedData;
// Compress
using(var compressedStream = new MemoryStream())
using(var gzs = new GZipOutputStream(compressedStream)) {
gzs.SetLevel(5);
gzs.Write(plainData, 0, plainData.Length);
gzs.Finish();
compressedData = compressedStream.ToArray();
}
Assert.IsNotNull(compressedData);
// Extract
using(var compressedStream = new MemoryStream(compressedData)) {
// compressedStream.Seek(0, SeekOrigin.Begin);
using(var gzs = new GZipInputStream(compressedStream))
using(var extractedStream = new MemoryStream()) {
StreamTool.CopyStreamToStream(gzs, extractedStream);
extractedData = extractedStream.ToArray();
}
}
Assert.IsNotNull(extractedData);
string extractedText = Encoding.UTF8.GetString(extractedData).TrimEnd('\0');
Assert.AreEqual(PlainText, extractedText);
}
示例4: GZipFldField
/**
* Construct a new GZipFldField object and load a field file
* from the specified filename.
*
* @throws IOException, InvalidFieldException, ApplicationException
*/
public GZipFldField(string filename) {
Stream file = new FileStream(filename, FileMode.Open);
Stream gzipStream = new GZipInputStream(file);
field = new FldField(gzipStream);
gzipStream.Close();
file.Close();
}
示例5: ExecuteTask
/// <summary>
/// Extracts the file from the gzip archive.
/// </summary>
protected override void ExecuteTask() {
try {
using (GZipInputStream gzs = new GZipInputStream(SrcFile.OpenRead())) {
Log(Level.Info, "Expanding '{0}' to '{1}' ({2} bytes).",
SrcFile.FullName, DestFile.FullName, gzs.Length);
// holds data from src file
byte[] data = new byte[8 * 1024];
// first read from input to ensure we're dealing with valid
// src file before we actually create the dest file
int size = gzs.Read(data, 0, data.Length);
// write expanded data to dest file
using (FileStream fs = new FileStream(DestFile.FullName, FileMode.Create, FileAccess.Write, FileShare.None)) {
while (size > 0) {
fs.Write(data, 0, size);
size = gzs.Read(data, 0, data.Length);
}
// close output stream
fs.Close();
}
// close input stream
gzs.Close();
}
} catch (IOException ex) {
throw new BuildException(string.Format(CultureInfo.InvariantCulture,
"Failed to expand '{0}' to '{1}'.", SrcFile.FullName,
DestFile.FullName), Location, ex);
} catch (GZipException ex) {
throw new BuildException(string.Format(CultureInfo.InvariantCulture,
"Invalid gzip file '{0}'.", SrcFile.FullName), Location, ex);
}
}
示例6: BigStream
public void BigStream()
{
window_ = new WindowedStream(0x3ffff);
outStream_ = new GZipOutputStream(window_);
inStream_ = new GZipInputStream(window_);
long target = 0x10000000;
readTarget_ = writeTarget_ = target;
Thread reader = new Thread(Reader);
reader.Name = "Reader";
reader.Start();
Thread writer = new Thread(Writer);
writer.Name = "Writer";
DateTime startTime = DateTime.Now;
writer.Start();
writer.Join();
reader.Join();
DateTime endTime = DateTime.Now;
TimeSpan span = endTime - startTime;
Console.WriteLine("Time {0} processes {1} KB/Sec", span, (target / 1024) / span.TotalSeconds);
}
示例7: GetDecompressedBytes
public static byte[] GetDecompressedBytes(this WWW www)
{
#if UNITY_STANDALONE_WIN || UNITY_WEBGL
string contentEncoding;
if (www.responseHeaders == null ||
!www.responseHeaders.TryGetValue(ContentEncodingHeaderName, out contentEncoding) ||
!contentEncoding.Equals(GzipContentEncodingValue, StringComparison.OrdinalIgnoreCase))
{
return www.bytes;
}
byte[] buffer = new byte[4096];
using (var stream = new MemoryStream(www.bytes))
using (var gzip = new GZipInputStream(stream))
using (var outMs = new MemoryStream(www.bytes.Length))
{
int bytesRead = 0;
while ((bytesRead = gzip.Read(buffer, 0, buffer.Length)) > 0)
{
outMs.Write(buffer,0, bytesRead);
}
return outMs.ToArray();
}
#else
return www.bytes;
#endif
}
示例8: Extract
public void Extract(string path, string dest_dir)
{
GZipInputStream gzstream = new GZipInputStream(new FileStream( path, FileMode.Open));
TarExtracter untar = new TarExtracter();
untar.Extract(gzstream, dest_dir);
gzstream.Close();
}
示例9: Decompress
private static byte[] Decompress(byte[] compressed)
{
using (var compressedMemoryStream = new MemoryStream(compressed))
{
var gZipInputStream = new GZipInputStream(compressedMemoryStream);
try
{
using (var unCompressedStream = new MemoryStream())
{
var noOfBytesReadTotal = 0;
const int blockSize = 2048;
var byteBlock = new byte[blockSize];
while (true)
{
var noOfBytesRead = gZipInputStream.Read(byteBlock, 0, byteBlock.Length);
if (noOfBytesRead <= 0)
{
break;
}
noOfBytesReadTotal += noOfBytesRead;
unCompressedStream.Write(byteBlock, 0, noOfBytesRead);
}
var decompressedWithoutTrailingZeros =
unCompressedStream.GetBuffer().Take(noOfBytesReadTotal);
return decompressedWithoutTrailingZeros.ToArray();
}
}
finally
{
gZipInputStream.Close();
}
}
}
示例10: GetResponseStream
// select the right decompression stream
public override Stream GetResponseStream()
{
try
{
Stream responseStream = _response.GetResponseStream();
Stream compressedStream = null;
if (_response.ContentEncoding == "gzip")
{
compressedStream = new
GZipInputStream(responseStream);
}
else if (_response.ContentEncoding == "deflate")
{
compressedStream = new
ZipInputStream(responseStream);
}
if (compressedStream == null)
compressedStream = responseStream;
if (compressedStream != null)
{
// Decompress
MemoryStream decompressedStream = new MemoryStream();
int totalSize = 0;
int size = 2048;
byte[] writeData = new byte[2048];
while (true)
{
size = compressedStream.Read(writeData, 0, size);
totalSize += size;
if (size > 0)
decompressedStream.Write(writeData, 0, size);
else
break;
}
if (compressedStream != responseStream)
responseStream.Close();
compressedStream.Close();
decompressedStream.Seek(0, SeekOrigin.Begin);
using (MemoryStream logstream = new MemoryStream(decompressedStream.GetBuffer()))
using (StreamReader sr = new StreamReader(logstream))
{
DebugHelper.WriteLogEntry("ResponseStream: " + sr.ReadToEnd());
}
decompressedStream.Seek(0, SeekOrigin.Begin);
return decompressedStream;
}
return compressedStream;
}
catch (Exception ex)
{
DebugHelper.WriteLogEntry(ex, "GZIP error");
return null;
}
}
示例11: TestMigration
public void TestMigration()
{
string dir = Path.Combine (Path.GetTempPath (), Path.GetRandomFileName ());
Directory.CreateDirectory (dir);
var assembly = Assembly.GetExecutingAssembly ();
using (Stream fs = assembly.GetManifestResourceStream ("longomatch.tar.gz")) {
using (Stream gzipStream = new GZipInputStream (fs)) {
using (TarArchive tarArchive = TarArchive.CreateInputTarArchive (gzipStream)) {
tarArchive.ExtractContents (dir);
}
}
}
CouchbaseStorageLongoMatch storage = new CouchbaseStorageLongoMatch (dir, "longomatch");
Assert.AreEqual (2, storage.RetrieveAll<SportsTeam> ().Count ());
Assert.AreEqual (1, storage.RetrieveAll<DashboardLongoMatch> ().Count ());
Assert.AreEqual (1, storage.RetrieveAll<ProjectLongoMatch> ().Count ());
SportsTeam team = storage.RetrieveAll<SportsTeam> ().First ();
Assert.DoesNotThrow (team.Load);
DashboardLongoMatch dashboard = storage.RetrieveAll<DashboardLongoMatch> ().First ();
Assert.DoesNotThrow (dashboard.Load);
ProjectLongoMatch project = storage.RetrieveAll<ProjectLongoMatch> ().First ();
Assert.DoesNotThrow (project.Load);
}
示例12: ExtractTar
/// <summary>
/// Extracts contents of GZipped Tar file to specified directory
/// </summary>
/// <param name="filename">Input .tar.gz file</param>
/// <param name="directory">Output directory</param>
public static void ExtractTar(string filename, string directory)
{
using (Stream inStream = File.OpenRead(filename))
using (Stream gzipStream = new GZipInputStream(inStream))
using (TarArchive tarArchive = TarArchive.CreateInputTarArchive(gzipStream))
tarArchive.ExtractContents(directory);
}
示例13: Resources
static Resources()
{
using ( MemoryStream memStream = new MemoryStream( FFTPatcher.TextEditor.Properties.Resources.Resources_tar, false ) )
using ( GZipInputStream gzStream = new GZipInputStream( memStream ) )
using ( TarInputStream tarStream = new TarInputStream( gzStream ) )
{
TarEntry entry;
entry = tarStream.GetNextEntry();
while ( entry != null )
{
if ( entry.Size != 0 && !string.IsNullOrEmpty( entry.Name ) )
{
if (entry.Name.EndsWith( ".xml" ))
{
XmlDocument doc = new XmlDocument();
doc.Load( tarStream );
resourceMapping[entry.Name] = doc;
}
else
{
byte[] bytes = new byte[entry.Size];
ICSharpCode.SharpZipLib.Core.StreamUtils.ReadFully( tarStream, bytes );
otherResources[entry.Name] = bytes;
}
}
entry = tarStream.GetNextEntry();
}
}
}
示例14: TestGZip
public void TestGZip()
{
MemoryStream ms = new MemoryStream();
GZipOutputStream outStream = new GZipOutputStream(ms);
byte[] buf = new byte[100000];
System.Random rnd = new Random();
rnd.NextBytes(buf);
outStream.Write(buf, 0, buf.Length);
outStream.Flush();
outStream.Finish();
ms.Seek(0, SeekOrigin.Begin);
GZipInputStream inStream = new GZipInputStream(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]);
}
}
示例15: TestGZip
public void TestGZip()
{
MemoryStream ms = new MemoryStream();
GZipOutputStream outStream = new GZipOutputStream(ms);
byte[] buf = new byte[100000];
System.Random rnd = new Random();
rnd.NextBytes(buf);
outStream.Write(buf, 0, buf.Length);
outStream.Flush();
outStream.Finish();
ms.Seek(0, SeekOrigin.Begin);
GZipInputStream inStream = new GZipInputStream(ms);
byte[] buf2 = new byte[buf.Length];
int currentIndex = 0;
int count = buf2.Length;
while (true) {
int numRead = inStream.Read(buf2, currentIndex, count);
if (numRead <= 0) {
break;
}
currentIndex += numRead;
count -= numRead;
}
Assert.AreEqual(0, count);
for (int i = 0; i < buf.Length; ++i) {
Assert.AreEqual(buf2[i], buf[i]);
}
}