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

C# GZip.GZipOutputStream类代码示例

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

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



GZipOutputStream类属于ICSharpCode.SharpZipLib.GZip命名空间,在下文中一共展示了GZipOutputStream类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

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


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


示例3: CreateTar

		/// <summary>
		/// Creates a GZipped Tar file from a source directory
		/// </summary>
		/// <param name="outputTarFilename">Output .tar.gz file</param>
		/// <param name="sourceDirectory">Input directory containing files to be added to GZipped tar archive</param>
		public static void CreateTar(string outputTarFilename, string sourceDirectory)
		{
			using (FileStream fs = new FileStream(outputTarFilename, FileMode.Create, FileAccess.Write, FileShare.None))
			using (Stream gzipStream = new GZipOutputStream(fs))
			using (TarArchive tarArchive = TarArchive.CreateOutputTarArchive(gzipStream))
				AddDirectoryFilesToTar(tarArchive, sourceDirectory, true);
		}
开发者ID:hexandr,项目名称:uLearn,代码行数:12,代码来源:ArchiveManager.cs


示例4: CtorErrMsg

        public static byte[] CtorErrMsg(string msg, NameValueCollection requestParam)
        {
            using (MemoryStream ms = new MemoryStream())
            {
                //包总长度
                int len = 0;
                long pos = 0;
                //包总长度,占位
                WriteValue(ms, len);
                int actionid = Convert.ToInt32(requestParam["actionid"]);
                //StatusCode
                WriteValue(ms, 10001);
                //msgid
                WriteValue(ms, Convert.ToInt32(requestParam["msgid"]));
                WriteValue(ms, msg);
                WriteValue(ms, actionid);
                WriteValue(ms, "st");
                //playerdata
                WriteValue(ms, 0);
                //固定0
                WriteValue(ms, 0);
                ms.Seek(pos, SeekOrigin.Begin);
                WriteValue(ms, (int)ms.Length);

                using (var gms = new MemoryStream())
                using (var gzs = new GZipOutputStream(gms))
                {
                    gzs.Write(ms.GetBuffer(), 0, (int)ms.Length);
                    gzs.Flush();
                    gzs.Close();
                    return gms.ToArray();
                }
            }
        }
开发者ID:0jpq0,项目名称:Scut,代码行数:34,代码来源:RequestParse.cs


示例5: CreateTarGzFile

        public string CreateTarGzFile(List<string> files, string destinationFolder)
        {
            var fileName = Path.Combine(destinationFolder, DateTime.Now.Ticks.ToString() + ".tar.gz");
            Stream outStream = File.Create(fileName);
            Stream gzoStream = new GZipOutputStream(outStream);
            TarArchive tarArchive = TarArchive.CreateOutputTarArchive(gzoStream);

            // Note that the RootPath is currently case sensitive and must be forward slashes e.g. "c:/temp"
            // and must not end with a slash, otherwise cuts off first char of filename
            // This is scheduled for fix in next release
            tarArchive.RootPath = destinationFolder.Replace('\\', '/');
            tarArchive.RootPath.TrimEnd("/".ToCharArray());

            TarEntry tarEntry = TarEntry.CreateEntryFromFile(destinationFolder);
            tarArchive.WriteEntry(tarEntry, false);

            foreach (string filename in files)
            {
                tarEntry = TarEntry.CreateEntryFromFile(filename);
                tarArchive.WriteEntry(tarEntry, true);
            }

            tarArchive.Close();

            return fileName;
        }
开发者ID:dragon753,项目名称:Deployer,代码行数:26,代码来源:TarForm.cs


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


示例7: GetDataSet

		public void GetDataSet()
		{
			SoapContext sc = HttpSoapContext.ResponseContext;
			if (null == sc)
			{
				throw new ApplicationException("Only SOAP requests allowed");
			}

			SqlConnection conn = new SqlConnection(@"data source=(local)\NetSDK;" +
				"initial catalog=Northwind;integrated security=SSPI");

			SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM customers", conn);
			DataSet ds = new DataSet("CustomerDS");
			da.Fill(ds, "Customers");
			
			// dispose of all objects that are no longer necessary
			da.Dispose();
			conn.Dispose();

			MemoryStream memoryStream = new MemoryStream(1024);
			GZipOutputStream gzipStream = new GZipOutputStream(memoryStream);
			ds.WriteXml(gzipStream);
			gzipStream.Finish();
			memoryStream.Seek(0, SeekOrigin.Begin);

			DimeAttachment dimeAttachment = new DimeAttachment("application/x-gzip",
				TypeFormatEnum.MediaType, 
				memoryStream);

			sc.Attachments.Add(dimeAttachment);
		}
开发者ID:JoeCooper,项目名称:SharpZipLib.Portable,代码行数:31,代码来源:Service1.asmx.cs


示例8: Compress

 /// <summary>
 /// 压缩文件为gz文件
 /// </summary>
 /// <param name="sourcefilename">压缩的文件路径</param>
 /// <param name="zipfilename">压缩后的gz文件路径</param>
 /// <returns></returns>
 public static bool Compress(string sourcefilename, string zipfilename)
 {
     bool blResult;//表示压缩是否成功的返回结果
     //为源文件创建读取文件的流实例
     FileStream srcFile = File.OpenRead(sourcefilename);
     //为压缩文件创建写入文件的流实例
     GZipOutputStream zipFile = new GZipOutputStream(File.Open(zipfilename, FileMode.Create));
     try
     {
         byte[] FileData = new byte[srcFile.Length];//创建缓冲数据
         srcFile.Read(FileData, 0, (int)srcFile.Length);//读取源文件
         zipFile.Write(FileData, 0, FileData.Length);//写入压缩文件
         blResult = true;
         return blResult;
     }
     catch
     {
         blResult = false;
         return blResult;
     }
     finally
     {
         srcFile.Close();//关闭源文件
         zipFile.Close();//关闭压缩文件
     }
 }
开发者ID:TaylorLi,项目名称:WorkStudioEnhance,代码行数:32,代码来源:GzipHelper.cs


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


示例10: Compress

        /// <summary>
        /// 지정된 데이타를 압축한다.
        /// </summary>
        /// <param name="input">압축할 Data</param>
        /// <returns>압축된 Data</returns>
        public override byte[] Compress(byte[] input) {
            if(IsDebugEnabled)
                log.Debug(CompressorTool.SR.CompressStartMsg);

            // check input data
            if(input.IsZeroLength()) {
                if(IsDebugEnabled)
                    log.Debug(CompressorTool.SR.InvalidInputDataMsg);

                return CompressorTool.EmptyBytes;
            }

            byte[] output;
            using(var compressedStream = new MemoryStream(input.Length)) {
                using(var gzs = new GZipOutputStream(compressedStream)) {
                    gzs.SetLevel(ZipLevel);
                    gzs.Write(input, 0, input.Length);
                    gzs.Finish();
                }
                output = compressedStream.ToArray();
            }

            if(IsDebugEnabled)
                log.Debug(CompressorTool.SR.CompressResultMsg, input.Length, output.Length, output.Length / (double)input.Length);

            return output;
        }
开发者ID:debop,项目名称:NFramework,代码行数:32,代码来源:SharpGZipCompressor.cs


示例11: Write

 /// <summary>
 /// Write content to the stream and have it compressed using gzip.
 /// </summary>
 /// <param name="buffer">The bytes to write</param>
 /// <param name="offset">The offset into the buffer to start reading bytes</param>
 /// <param name="count">The number of bytes to write</param>
 public override void Write(byte[] buffer, int offset, int count) {
   //      GZipOutputStream stream = new GZipOutputStream(BaseStream);
   //      stream.Write(buffer, offset, count);
   //      stream.Finish();
   if (m_stream == null)
     m_stream = new GZipOutputStream(BaseStream);
   m_stream.Write(buffer, offset, count);
 }
开发者ID:JoeCooper,项目名称:SharpZipLib.Portable,代码行数:14,代码来源:GZipFilter.cs


示例12: GZip

 public static void GZip(FileInfo fi)
 {
     byte[] dataBuffer = new byte[4096];
     using (Stream s = new GZipOutputStream(File.Create(fi.FullName + ".gz")))
     using (FileStream fs = fi.OpenRead())
     {
         StreamUtils.Copy(fs, s, dataBuffer);
     }
 }
开发者ID:romhackingvn,项目名称:Alpha-Translation,代码行数:9,代码来源:Program.cs


示例13: compress_gzip

 /// <summary>
 /// Compresses byte array using gzip
 /// Compressed data is returned as a byte array
 /// </summary>
 /// <param name="inBytes">The bytes to compress</param>
 public static byte[] compress_gzip(byte[] inBytes)
 {
     MemoryStream ContentsGzippedStream = new MemoryStream();	//create the memory stream to hold the compressed file
     Stream s = new GZipOutputStream(ContentsGzippedStream);		//create the gzip filter
     s.Write(inBytes, 0, inBytes.Length);				        //write the file contents to the filter
     s.Flush();													//make sure everythings ready
     s.Close();													//close and write the compressed data to the memory stream
     return ContentsGzippedStream.ToArray();
 }
开发者ID:andyhebear,项目名称:extramegablob,代码行数:14,代码来源:Helpers.cs


示例14: CompressBytes

 /// <summary>
 /// 压缩字节数组
 /// 返回:已压缩的字节数组
 /// </summary>
 /// <param name="bytData">待压缩的字节数组</param>
 /// <returns></returns>
 public static byte[] CompressBytes(byte[] data)
 {
     MemoryStream o = new MemoryStream();
     Stream s = new ICSharpCode.SharpZipLib.GZip.GZipOutputStream(o);
     s.Write(data, 0, data.Length);
     s.Close();
     o.Flush();
     o.Close();
     return o.ToArray();
 }
开发者ID:nethz,项目名称:UnityGame,代码行数:16,代码来源:JsonDataAffix.cs


示例15: Compress

 public static string Compress(string sourceFile){
     byte[] dataBuffer = new byte[4096];
     string destFile = sourceFile + ".gz";
     using (Stream gs = new GZipOutputStream(File.Create(destFile))) {
         using (FileStream fs = File.OpenRead(sourceFile)) {
             StreamUtils.Copy(fs, gs, dataBuffer);
         }
     }
     return destFile;
 }
开发者ID:s7loves,项目名称:mypowerscgl,代码行数:10,代码来源:GZipHelper.cs


示例16: Serialize

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


示例17: CompressByte

 /// <summary>
 /// 压缩byte数组
 /// </summary>
 /// <param name="inBytes">需要压缩的byte数组</param>
 /// <returns>压缩好的byte数组</returns>
 public static byte[] CompressByte(byte[] inBytes)
 {
     MemoryStream outStream = new MemoryStream();
     Stream zipStream = new GZipOutputStream(outStream);
     zipStream.Write(inBytes, 0, inBytes.Length);
     zipStream.Close();
     byte[] outData = outStream.ToArray();
     outStream.Close();
     return outData;
 }
开发者ID:songques,项目名称:CSSIM_Solution,代码行数:15,代码来源:ZIP.cs


示例18: returnZippedbyteArray

        public static byte[] returnZippedbyteArray(string stringToZip)
        {
            MemoryStream memStream = new MemoryStream();
            Stream compressedStream = new GZipOutputStream(memStream);
            byte[] byteArrayToZip = Encoding.UTF8.GetBytes(stringToZip.ToCharArray());

            compressedStream.Write(byteArrayToZip ,0,byteArrayToZip.Length);
            compressedStream.Flush();
            compressedStream.Close();
            return memStream.ToArray();
        }
开发者ID:asr340,项目名称:owasp-code-central,代码行数:11,代码来源:zip.cs


示例19: SaveFile

 public static void SaveFile(string fileName, byte[] data)
 {
     if (File.Exists(fileName)) File.Delete(fileName);
     using (FileStream targetStream = File.OpenWrite(fileName))
     {
         using (GZipOutputStream targetStreamGzip = new GZipOutputStream(targetStream))
         {
             MemoryStream saveTemp = new MemoryStream(data);
             CopyStream(saveTemp, targetStreamGzip);
         }
     }
 }
开发者ID:Badaro,项目名称:SRTJSaveConverter,代码行数:12,代码来源:GZipUtil.cs


示例20: Compress

		/// <summary>
		/// 压缩字节数组
		/// </summary>
		/// <param name="inputBytes">Input bytes.</param>
		public static byte[] Compress (byte[] inputBytes)
		{
			using (var outStream = new MemoryStream ())
			{
				using (var zipStream = new GZipOutputStream (outStream))
				{
					zipStream.Write (inputBytes, 0, inputBytes.Length);
					zipStream.Close ();	
				}
				return outStream.ToArray ();
			}	
		}
开发者ID:Venbb,项目名称:mgame,代码行数:16,代码来源:ByteEx.cs



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C# Tar.TarEntry类代码示例发布时间:2022-05-26
下一篇:
C# GZip.GZipInputStream类代码示例发布时间: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