本文整理汇总了C#中ICSharpCode.SharpZipLib.GZip.GZipInputStream.Close方法的典型用法代码示例。如果您正苦于以下问题:C# GZipInputStream.Close方法的具体用法?C# GZipInputStream.Close怎么用?C# GZipInputStream.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICSharpCode.SharpZipLib.GZip.GZipInputStream
的用法示例。
在下文中一共展示了GZipInputStream.Close方法的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: 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();
}
示例3: 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();
}
示例4: 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();
}
}
}
示例5: Decompress
public string Decompress(string filename)
{
StringBuilder result = null;
try
{
Stream s = new GZipInputStream(File.OpenRead(filename));
result = new StringBuilder(8192);
UTF7Encoding encoding = new UTF7Encoding(true);
int size = 2048;
byte[] writeData = new byte[2048];
while (true)
{
size = s.Read(writeData, 0, size);
if (size > 0)
{
result.Append(encoding.GetString(writeData,0,size));
}
else
{
break;
}
}
s.Close();
} // end try
catch (GZipException)
{
throw new Exception("Error: The file being read contains invalid data.");
}
catch (FileNotFoundException)
{
throw new Exception("Error:The file specified was not found.");
}
catch (ArgumentException)
{
throw new Exception("Error: path is a zero-length string, contains only white space, or contains one or more invalid characters");
}
catch (PathTooLongException)
{
throw new Exception("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)
{
throw new Exception("Error: The specified path is invalid, such as being on an unmapped drive.");
}
catch (IOException)
{
throw new Exception("Error: An I/O error occurred while opening the file.");
}
catch (UnauthorizedAccessException)
{
throw new Exception("Error: path specified a file that is read-only, the path is a directory, or caller does not have the required permissions.");
}
return result.ToString();
}
示例6: UnTarGzFiles
/// <summary>
/// Extract tar.gz files to disk
/// </summary>
/// <param name="source">Tar.gz source file</param>
/// <param name="destination">Location folder to unzip to</param>
public static void UnTarGzFiles(string source, string destination)
{
var inStream = File.OpenRead(source);
var gzipStream = new GZipInputStream(inStream);
var tarArchive = TarArchive.CreateInputTarArchive(gzipStream);
tarArchive.ExtractContents(destination);
tarArchive.Close();
gzipStream.Close();
inStream.Close();
}
示例7: ExtractTgz
private void ExtractTgz(string compressedFile, string destination)
{
Stream inStream = File.OpenRead(compressedFile);
Stream gzipStream = new GZipInputStream(inStream);
TarArchive tarArchive = TarArchive.CreateInputTarArchive(gzipStream);
tarArchive.ExtractContents(destination);
tarArchive.Close();
gzipStream.Close();
inStream.Close();
}
示例8: ExtractTGZ
public static void ExtractTGZ(String gzArchiveName, String destFolder)
{
Stream inStream = File.OpenRead(gzArchiveName);
Stream gzipStream = new GZipInputStream(inStream);
TarArchive tarArchive = TarArchive.CreateInputTarArchive(gzipStream);
tarArchive.ExtractContents(destFolder);
tarArchive.Close();
gzipStream.Close();
inStream.Close();
}
示例9: Uncompression
/// <summary>
/// 解压缩
/// </summary>
public static byte[] Uncompression(byte[] src)
{
if (!IsGZip(src)) return src;
GZipInputStream gis = new GZipInputStream(new MemoryStream(src));
MemoryStream ms = new MemoryStream();
int count = 0;
byte[] tmp = new byte[4096];
while ((count = gis.Read(tmp, 0, tmp.Length)) > 0)
{
ms.Write(tmp, 0, count);
}
gis.Close();
return ms.ToArray();
}
示例10: DeCompress
public static byte[] DeCompress( byte[] bytesToDeCompress )
{
byte[] rebyte = new byte[ bytesToDeCompress.Length * 20 ];
MemoryStream ms = new MemoryStream( bytesToDeCompress );
MemoryStream outStream = new MemoryStream();
GZipInputStream s = new GZipInputStream( ms );
int read = s.Read( rebyte , 0 , rebyte.Length );
while ( read > 0 )
{
outStream.Write( rebyte, 0 , read );
read = s.Read( rebyte , 0, rebyte.Length );
}
s.Close();
return outStream.ToArray();
}
示例11: ExtractTgz
public static bool ExtractTgz(string strSourceFilename, string strDestFolder)
{
try
{
Stream inStream = File.OpenRead(strSourceFilename);
Stream gzipStream = new GZipInputStream(inStream);
TarArchive tarArchive = TarArchive.CreateInputTarArchive(gzipStream);
tarArchive.ExtractContents(strDestFolder);
tarArchive.CloseArchive();
gzipStream.Close();
inStream.Close();
return true;
} catch(Exception)
{
// Log error
return false;
}
}
示例12: Decompress
/// <summary>
/// 解压字节数组
/// </summary>
/// <param name="inputBytes">Input bytes.</param>
public static byte[] Decompress (byte[] inputBytes)
{
using (var inputStream = new MemoryStream (inputBytes))
{
using (var zipStream = new GZipInputStream (inputStream))
{
using (var outStream = new MemoryStream ())
{
int size = 2048;
var outBytes = new byte[size];
while (size > 0)
{
size = zipStream.Read (outBytes, 0, size);
if (size > 0) outStream.Write (outBytes, 0, size);
}
zipStream.Close ();
return outStream.ToArray ();
}
}
}
}
示例13: GUnzipBestEffort
/// <summary> Returns an gunzipped copy of the input array, truncated to
/// <code>sizeLimit</code> bytes, if necessary. If the gzipped input
/// has been truncated or corrupted, a best-effort attempt is made to
/// unzip as much as possible. If no data can be extracted
/// <code>null</code> is returned.
/// </summary>
public static byte[] GUnzipBestEffort(System.IO.Stream srcStream, int sizeLimit)
{
try
{
// decompress using GZIPInputStream
System.IO.MemoryStream outStream = new System.IO.MemoryStream(EXPECTED_COMPRESSION_RATIO * (Int32)srcStream.Length);
GZipInputStream inStream = new GZipInputStream(srcStream);
byte[] buf = new byte[BUF_SIZE];
int size = BUF_SIZE;
int written = 0;
while (true)
{
size = inStream.Read(buf, 0, size);
if (size <= 0)
{
break;
}
if ((written + size) > sizeLimit)
{
outStream.Write(buf, 0, sizeLimit - written);
}
outStream.Write(buf, 0, size);
written += size;
}
inStream.Close();
return outStream.ToArray();
}
catch(Exception ex)
{
System.Diagnostics.Trace.WriteLine(ex.Message);
return null;
}
}
示例14: UnzipString
/// unzip a base64 encoded string and return the original utf8 string using gzip
public static string[] UnzipString(string ACompressedString)
{
List <String>Result = new List <string>();
Byte[] compressedBuffer = Convert.FromBase64String(ACompressedString);
MemoryStream memoryStream = new MemoryStream(compressedBuffer);
GZipInputStream gzStream = new GZipInputStream(memoryStream);
StreamReader sr = new StreamReader(gzStream);
while (!sr.EndOfStream)
{
Result.Add(sr.ReadLine());
}
sr.Close();
gzStream.Close();
return Result.ToArray();
}
示例15: InputStreamOwnership
public void InputStreamOwnership()
{
TrackedMemoryStream memStream = new TrackedMemoryStream();
GZipInputStream s = new GZipInputStream(memStream);
Assert.IsFalse(memStream.IsClosed, "Shouldnt be closed initially");
Assert.IsFalse(memStream.IsDisposed, "Shouldnt be disposed initially");
s.Close();
Assert.IsTrue(memStream.IsClosed, "Should be closed after parent owner close");
Assert.IsTrue(memStream.IsDisposed, "Should be disposed after parent owner close");
memStream = new TrackedMemoryStream();
s = new GZipInputStream(memStream);
Assert.IsFalse(memStream.IsClosed, "Shouldnt be closed initially");
Assert.IsFalse(memStream.IsDisposed, "Shouldnt be disposed initially");
s.IsStreamOwner = false;
s.Close();
Assert.IsFalse(memStream.IsClosed, "Should not be closed after parent owner close");
Assert.IsFalse(memStream.IsDisposed, "Should not be disposed after parent owner close");
}