当前位置: 首页>>代码示例>>C#>>正文


C# GZipInputStream.Close方法代码示例

本文整理汇总了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();
                    }
                }
            }
        }
开发者ID:danni95,项目名称:Core,代码行数:30,代码来源:SharpCompressionProvider.cs

示例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();
	}
开发者ID:puring0815,项目名称:OpenKore,代码行数:13,代码来源:GZipFldField.cs

示例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();
 }
开发者ID:GNOME,项目名称:capuchin,代码行数:7,代码来源:TarGzExtracter.cs

示例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();
         }
     }
 }
开发者ID:1pindsvin,项目名称:yagni,代码行数:33,代码来源:UudecodedUnGZipper.cs

示例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();
        }
开发者ID:BackupTheBerlios,项目名称:dufftv-svn,代码行数:59,代码来源:GzipDecompressor.cs

示例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();
 }
开发者ID:intelliBrain,项目名称:Lean,代码行数:15,代码来源:Compression.cs

示例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();
        }
开发者ID:keep3r,项目名称:Sonarr,代码行数:12,代码来源:ArchiveService.cs

示例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();
        }
开发者ID:ADTC,项目名称:VietOCR,代码行数:12,代码来源:FileExtractor.cs

示例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();
 }
开发者ID:zeronely,项目名称:View,代码行数:17,代码来源:GZipUtil.cs

示例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();
    }
开发者ID:GHunique,项目名称:MyU3dFrame,代码行数:19,代码来源:GameDefine.cs

示例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;
            }
        }
开发者ID:DynamicDevices,项目名称:dta,代码行数:21,代码来源:ArchiveHelper.cs

示例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 ();
					}
				}
			}
		}
开发者ID:Venbb,项目名称:mgame,代码行数:25,代码来源:ByteEx.cs

示例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;
			}
		}
开发者ID:limingyao,项目名称:Crawler,代码行数:42,代码来源:GZIPUtils.cs

示例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();
        }
开发者ID:Davincier,项目名称:openpetra,代码行数:21,代码来源:PackTools.cs

示例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");

		}
开发者ID:rollingthunder,项目名称:slsharpziplib,代码行数:26,代码来源:GZipTests.cs


注:本文中的ICSharpCode.SharpZipLib.GZip.GZipInputStream.Close方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。