• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# GZip.GZipInputStream类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中ICSharpCode.SharpZipLib.GZip.GZipInputStream的典型用法代码示例。如果您正苦于以下问题:C# GZipInputStream类的具体用法?C# GZipInputStream怎么用?C# GZipInputStream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



GZipInputStream类属于ICSharpCode.SharpZipLib.GZip命名空间,在下文中一共展示了GZipInputStream类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: 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;
        }
开发者ID:PokeD,项目名称:TMXParserPCL,代码行数:25,代码来源:Data.cs


示例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);
        }
开发者ID:debop,项目名称:NFramework,代码行数:34,代码来源:SharpGZipCompressorFixture.cs


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


示例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);
            }
        }
开发者ID:RoastBoy,项目名称:nant,代码行数:37,代码来源:GUnzip.cs


示例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);
        }
开发者ID:jeske,项目名称:StepsDB-alpha,代码行数:27,代码来源:GZipTests.cs


示例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
        }
开发者ID:urgamedev,项目名称:RenderCubes,代码行数:28,代码来源:WWWExtensions.cs


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


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


示例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;
            }
        }
开发者ID:xorkrus,项目名称:vk_wm,代码行数:61,代码来源:CompressedWebResponse.cs


示例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);
        }
开发者ID:LongoMatch,项目名称:longomatch,代码行数:28,代码来源:TestDatabaseMigrationV1.cs


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


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

            }
        }
开发者ID:Glain,项目名称:FFTPatcher,代码行数:31,代码来源:Resources.cs


示例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]);
            }
        }
开发者ID:foresightbrand,项目名称:brandqq,代码行数:30,代码来源:GZipTests.cs


示例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]);
			}
		}
开发者ID:rollingthunder,项目名称:slsharpziplib,代码行数:35,代码来源:GZipTests.cs


示例16: 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


示例17: Untgz

 public static void Untgz(Stream stream, string outDirPath)
 {
     using (var inputStream = new GZipInputStream(stream)) {
         var archive = TarArchive.CreateInputTarArchive(inputStream);
         archive.AsciiTranslate = false;
         archive.ExtractContents(outDirPath);
     }
 }
开发者ID:UnicoenProject,项目名称:UNICOEN-Test,代码行数:8,代码来源:Extractor.cs


示例18: Extract

 internal static void Extract(string filename)
 {
     using (Stream s = new GZipInputStream(File.OpenRead(filename)))
     using (FileStream fs = File.Create(filename + ".work"))
     {
         StreamUtils.Copy(s, fs, new byte[4096]);
     }
 }
开发者ID:vsukhoml,项目名称:gcdashboard,代码行数:8,代码来源:DataLoadHelper.cs


示例19: Import

 public WikiContent Import(string filename, Stream stream)
 {
     _Log.Debug("Loading from {0}", FormatExtension);
     filename = Path.GetFileNameWithoutExtension(filename);
     using (var gzip = new GZipInputStream(stream))
     {
         return WikiImporter.ImportFrom(filename, gzip, this);
     }
 }
开发者ID:kapitanov,项目名称:mwiki_pub,代码行数:9,代码来源:WikiGzArchiveImporter.cs


示例20: Deserialize

 public static object Deserialize(byte[] data)
 {
     MemoryStream ms = new MemoryStream(data);
     using (GZipInputStream stm = new GZipInputStream(ms))
     {
         BinaryFormatter bf = new BinaryFormatter(new RemotingSurrogateSelector(), new StreamingContext(StreamingContextStates.Persistence));
         return bf.Deserialize(stm);
     }
 }
开发者ID:alasdairhurst,项目名称:nginn,代码行数:9,代码来源:SerializationUtil.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# GZip.GZipOutputStream类代码示例发布时间:2022-05-26
下一篇:
C# Encryption.PkzipClassicManaged类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap