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


C# GZipOutputStream.SetLevel方法代码示例

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


在下文中一共展示了GZipOutputStream.SetLevel方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TestExtractArchiveTarGzCreateContainer

        public void TestExtractArchiveTarGzCreateContainer()
        {
            CloudFilesProvider provider = (CloudFilesProvider)Bootstrapper.CreateObjectStorageProvider();
            string containerName = TestContainerPrefix + Path.GetRandomFileName();
            string sourceFileName = "DarkKnightRises.jpg";
            byte[] content = File.ReadAllBytes("DarkKnightRises.jpg");
            using (MemoryStream outputStream = new MemoryStream())
            {
                using (GZipOutputStream gzoStream = new GZipOutputStream(outputStream))
                {
                    gzoStream.IsStreamOwner = false;
                    gzoStream.SetLevel(9);
                    using (TarOutputStream tarOutputStream = new TarOutputStream(gzoStream))
                    {
                        tarOutputStream.IsStreamOwner = false;
                        TarEntry entry = TarEntry.CreateTarEntry(containerName + '/' + sourceFileName);
                        entry.Size = content.Length;
                        tarOutputStream.PutNextEntry(entry);
                        tarOutputStream.Write(content, 0, content.Length);
                        tarOutputStream.CloseEntry();
                        tarOutputStream.Close();
                    }
                }

                outputStream.Flush();
                outputStream.Position = 0;
                ExtractArchiveResponse response = provider.ExtractArchive(outputStream, "", ArchiveFormat.TarGz);
                Assert.IsNotNull(response);
                Assert.AreEqual(1, response.CreatedFiles);
                Assert.IsNotNull(response.Errors);
                Assert.AreEqual(0, response.Errors.Count);
            }

            using (MemoryStream downloadStream = new MemoryStream())
            {
                provider.GetObject(containerName, sourceFileName, downloadStream, verifyEtag: true);
                Assert.AreEqual(content.Length, GetContainerObjectSize(provider, containerName, sourceFileName));

                downloadStream.Position = 0;
                byte[] actualData = new byte[downloadStream.Length];
                downloadStream.Read(actualData, 0, actualData.Length);
                Assert.AreEqual(content.Length, actualData.Length);
                using (MD5 md5 = MD5.Create())
                {
                    byte[] contentMd5 = md5.ComputeHash(content);
                    byte[] actualMd5 = md5.ComputeHash(actualData);
                    Assert.AreEqual(BitConverter.ToString(contentMd5), BitConverter.ToString(actualMd5));
                }
            }

            /* Cleanup
             */
            provider.DeleteContainer(containerName, deleteObjects: true);
        }
开发者ID:alanquillin,项目名称:openstack.net,代码行数:54,代码来源:UserObjectStorageTests.cs

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

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

示例4: Compress

        private const int COMPRESS_LEVEL = 7;// 0-9, 9 being the highest compression
        #endregion

        #region ICompressionProvider Members

        public byte[] Compress(byte[] data)
        {
            using (var outputStream = new MemoryStream())
            {
                using (var compressStream = new GZipOutputStream(outputStream))
                {
                    compressStream.SetLevel(COMPRESS_LEVEL);
                    compressStream.Write(data, 0, data.Length);
                    compressStream.Finish();
                    compressStream.Close();
                    return outputStream.ToArray();
                }
            }
        }
开发者ID:danni95,项目名称:Core,代码行数:19,代码来源:SharpCompressionProvider.cs

示例5: CompressFile

        public void CompressFile(string inFilePath, string outFilePath)
        {
            using (FileStream inFileStream =
                Util.IO.OpenFileStreamForReading(inFilePath)
                //new FileStream(inFilePath, FileMode.Open, FileAccess.Read)
                )
            {
                using (FileStream outFileStream = new FileStream(outFilePath, FileMode.Create, FileAccess.Write))
                {
                    using (var compressStream = new GZipOutputStream(outFileStream))
                    {
                        compressStream.SetLevel(COMPRESS_LEVEL);
                        byte[] buffer = new byte[BUFFER_SIZE];
                        ICSharpCode.SharpZipLib.Core.StreamUtils.Copy(inFileStream, compressStream, buffer);
                    }
                }
            }

            /*
            using (FileStream inFileStream =
                Util.IO.OpenFileStreadForReading(inFilePath)
                //new FileStream(inFilePath, FileMode.Open, FileAccess.Read)
                )
            {
                using (FileStream outFileStream = new FileStream(outFilePath, FileMode.Create, FileAccess.Write))
                {
                    using (var compressStream = new GZipOutputStream(outFileStream))
                    {
                        compressStream.SetLevel(COMPRESS_LEVEL);
                        byte[] buffer = new byte[BUFFER_SIZE];
                        while(true)
                        {
                            int size = inFileStream.Read(buffer, 0, buffer.Length);
                            if (size > 0)
                            {
                                compressStream.Write(buffer, 0, size);
                            }
                            else
                            {
                                break;
                            }
                        }
                        compressStream.Finish();
                        compressStream.Close();
                    }
                }
            }
             */            
        }
开发者ID:danni95,项目名称:Core,代码行数:49,代码来源:SharpCompressionProvider.cs

示例6: GzipCompressFile

 public static void GzipCompressFile(string inputPath, string outputPath, int compressionLevel)
 {
     using (var inputStream = new FileStream(inputPath, FileMode.Open, FileAccess.Read))
     {
         using (var outputStream = new FileStream(outputPath, FileMode.Create, FileAccess.Write))
         {
             using (var gzipStream = new GZipOutputStream(outputStream))
             {
                 gzipStream.SetLevel(compressionLevel);
                 int size;
                 byte[] data = new byte[_defaultBufferSize];
                 do
                 {
                     size = inputStream.Read(data, 0, data.Length);
                     gzipStream.Write(data, 0, size);
                 } while (size > 0);
             }
         }
     }
 }
开发者ID:jivkopetiov,项目名称:GzipApp,代码行数:20,代码来源:ZipService.cs

示例7: Write

		public override void Write(byte[] value)
		{
			var compressedStream = new MemoryStream();
			try
			{
				using (var inputStream = new MemoryStream(value))
				{
					using (var compressionStream = new GZipOutputStream(compressedStream))
					{
						compressionStream.SetLevel(9);
						inputStream.CopyTo(compressionStream);
						compressionStream.Flush();
					}
				}

				var compressedData = compressedStream.ToArray();
				_lock.Wait();

				using (var outputStream = File.OpenWrite(_filePath))
				{
					outputStream.Position = outputStream.Length;
					outputStream.Write(compressedData, 0, compressedData.Length);
					outputStream.Flush();
				}
			}
			finally
			{
				compressedStream.Dispose();
				_lock.Release();
			}

			var info = new FileInfo(_filePath);
			var bufferSize = info.Length;
			if (bufferSize > MaxBufferSize)
			{
				Flush();
			}
		}
开发者ID:smartpcr,项目名称:bigdata2,代码行数:38,代码来源:DiskEventStore.cs

示例8: Create

        /// <summary>
        /// Creates the Transformation Block to GZip compress.
        /// </summary>
        /// <param name="level">The compression level.</param>
        /// <param name="options">The options.</param>
        /// <returns>TransformBlock&lt;System.Byte[], System.Byte[]&gt;.</returns>
        public static TransformBlock<byte[], byte[]> Create(int level, ExecutionDataflowBlockOptions options)
        {
            return new TransformBlock<byte[], byte[]>(data =>
            {
                using (var output = new MemoryStream())
                {
                    using (var input = new MemoryStream(data))
                    using (var compression = new GZipOutputStream(output))
                    using (Logger.BeginTimedOperation("GZipOutputStream", null, LogEventLevel.Debug))
                    {
                        compression.SetLevel(level);
                        input.CopyTo(compression);
                        compression.Flush();
                    }

                    var result = output.ToArray();

                    Logger.Debug("Compressed {InputSize} bytes to {OutputSize} ({Compression:00}%)", data.Length, result.Length, result.Length * 100M / data.Length);

                    return result;
                }

            }, options);
        }
开发者ID:bradsjm,项目名称:AprsEventHubDemo,代码行数:30,代码来源:GZip.cs

示例9: ToCompressedByteArray

        public byte[] ToCompressedByteArray()
        {
            byte[] returnArray;

            byte[] streambuff = new byte[(XSize * YSize * ZSize) * Voxel.BYTE_SIZE];
            byte[] buffer = new byte[Voxel.BYTE_SIZE];
            int o = 0;
            for (int x = 0; x < XSize; x++)
                for (int y = 0; y < YSize; y++)
                    for (int z = 0; z < ZSize; z++)
                    {
                        buffer = Voxels[x + XSize * (y + YSize * z)].ToBytes();
                        for (int i = 0; i < Voxel.BYTE_SIZE; i++)
                        {
                            streambuff[o] = buffer[i];
                            o++;
                        }
                    }

            using (var ms = new MemoryStream())
            {

                using (var gzs = new GZipOutputStream(ms))
                {
                    gzs.SetLevel(1);
                    gzs.Write(streambuff, 0, streambuff.Length);
                }

                returnArray = ms.ToArray();
            }

            return returnArray;
        }
开发者ID:bdjewkes,项目名称:trollplayer,代码行数:33,代码来源:Frame.cs

示例10: Save

	public override void Save(Stream stream) {
		GZipOutputStream gzipStream = new GZipOutputStream(stream);
		gzipStream.IsStreamOwner = true;
		gzipStream.SetLevel(9);
		field.Save(gzipStream);
	}
开发者ID:puring0815,项目名称:OpenKore,代码行数:6,代码来源:GZipFldField.cs

示例11: Compress

        /// <summary>
        /// Compress a given file into Tar archive.
        /// </summary>
        public void Compress()
        {
            Common.ValidateOverwrite(this.overwriteTarget, this.target);
            DirectoryInfo dir = new DirectoryInfo(Path.GetDirectoryName(this.source));
            this.Log(String.Format("Archiving: [{0}] -> [{1}].", this.source, this.target), LogLevel.Minimal);

            if (tarLevel == TarCompressionLevel.None)
            {
                using (Stream outStream = File.Create(this.target))
                {
                    ArchiveFile(outStream, dir);
                }
            }
            else if (tarLevel == TarCompressionLevel.BZip2)
            {
                using (BZip2OutputStream bz2Stream = new BZip2OutputStream(File.Create(this.target), 9))
                {
                    ArchiveFile(bz2Stream, dir);
                }
            }
            else if (tarLevel == TarCompressionLevel.GZip)
            {
                using (GZipOutputStream gzoStream = new GZipOutputStream(File.Create(this.target)))
                {
                    gzoStream.SetLevel(9);
                    ArchiveFile(gzoStream, dir);
                }
            }

            this.Log(String.Format("Successfully Archived: [{0}] -> [{1}].", this.source, this.target), LogLevel.Minimal);
            Common.RemoveFile(this.removeSource, this.source);
        }
开发者ID:svn2github,项目名称:SSIS-Extensions,代码行数:35,代码来源:TarManager.cs

示例12: flush

        public void flush()
        {
            byte[] uncompressed_bytes = uncompressed_output.ToArray();

            // write uncompressed size to output
            new BinaryWriter(output).Write((UInt32)uncompressed_bytes.Length);

            // write the compressed data
            GZipOutputStream zipstream = new GZipOutputStream(this.output);
            zipstream.SetLevel(1); // 0 is no compression, 9 is best compression (slowest)
            zipstream.Write(uncompressed_bytes, 0, uncompressed_bytes.Length);
            zipstream.Finish();
        }
开发者ID:jeske,项目名称:StepsDB-alpha,代码行数:13,代码来源:SegmentBlockCompressed.cs

示例13: ReadDrive

        /// <summary>
        /// Read data direct from drive to file
        /// </summary>
        /// <param name="driveLetter"></param>
        /// <param name="fileName"></param>
        /// <param name="eCompType"></param>
        /// <returns></returns>
        public bool ReadDrive(string driveLetter, string fileName, EnumCompressionType eCompType, bool bUseMBR)
        {
            IsCancelling = false;

            var dtStart = DateTime.Now;

            //
            // Map to physical drive
            //
            var physicalDrive = _diskAccess.GetPhysicalPathForLogicalPath(driveLetter);
            if(string.IsNullOrEmpty(physicalDrive))
            {
                LogMsg(Resources.Disk_WriteDrive_Error__Couldn_t_map_partition_to_physical_drive);
                _diskAccess.UnlockDrive();
                return false;
            }

            //
            // Lock logical drive
            //
            var success = _diskAccess.LockDrive(driveLetter);
            if (!success)
            {
                LogMsg(Resources.Disk_WriteDrive_Failed_to_lock_drive);
                return false;
            }

            //
            // Get drive size
            //
            var driveSize = _diskAccess.GetDriveSize(physicalDrive);
            if(driveSize <= 0)
            {
                LogMsg(Resources.Disk_WriteDrive_Failed_to_get_device_size);
                _diskAccess.UnlockDrive();
                return false;
            }

            var readSize = driveSize;

            //
            // Open the physical drive
            //
            var physicalHandle = _diskAccess.Open(physicalDrive);
            if (physicalHandle == null)
            {
                LogMsg(Resources.Disk_WriteDrive_Failed_to_open_physical_drive);
                _diskAccess.UnlockDrive();
                return false;
            }

            //
            // Start doing the read
            //

            var buffer = new byte[Globals.MaxBufferSize];
            var offset = 0L;

            using(var basefs = (Stream)new FileStream(fileName, FileMode.Create, FileAccess.Write))
            {
                Stream fs;

                switch (eCompType)
                {
                    case EnumCompressionType.Zip:
                        var zfs = new ZipOutputStream(basefs);

                        // Default to middle of the range compression
                        zfs.SetLevel(Globals.CompressionLevel);

                        var fi = new FileInfo(fileName);
                        var entryName = fi.Name;
                        entryName = entryName.ToLower().Replace(".zip", "");
                        entryName = ZipEntry.CleanName(entryName);
                        var zipEntry = new ZipEntry(entryName) {DateTime = fi.LastWriteTime};
                        zfs.IsStreamOwner = true;

                        // Todo: Consider whether size needs setting for older utils ?

                        zfs.PutNextEntry(zipEntry);

                        fs = zfs;

                        break;

                    case EnumCompressionType.Gzip:

                        var gzis = new GZipOutputStream(basefs);
                        gzis.SetLevel(Globals.CompressionLevel);
                        gzis.IsStreamOwner = true;

                        fs = gzis;

//.........这里部分代码省略.........
开发者ID:ArturBaykov,项目名称:DiskImager,代码行数:101,代码来源:Disk.cs

示例14: Compress

        public static byte[] Compress(byte[] buffer)
        {
            Log.DebugFormat("Initial buffer size {0}",buffer.Length);
            MemoryStream ms = new MemoryStream();
            //GZipStream zip = new GZipStream(ms, CompressionMode.Compress, true);
            GZipOutputStream zip = new GZipOutputStream(ms) { IsStreamOwner = false };
            zip.SetLevel(9);
            //BZip2OutputStream zip = new BZip2OutputStream(ms) { IsStreamOwner = false };
            zip.Write(buffer, 0, buffer.Length);
            zip.Close();
            ms.Position = 0;

            //MemoryStream outStream = new MemoryStream();

            byte[] compressed = new byte[ms.Length];
            ms.Read(compressed, 0, compressed.Length);
            Log.DebugFormat("Compressed buffer size {0}", compressed.Length);

            byte[] gzBuffer = new byte[compressed.Length + 4];
            Buffer.BlockCopy(compressed, 0, gzBuffer, 4, compressed.Length);
            Buffer.BlockCopy(BitConverter.GetBytes(buffer.Length), 0, gzBuffer, 0, 4);
            return gzBuffer;
        }
开发者ID:andreyu,项目名称:Reports,代码行数:23,代码来源:RequestAttachment.cs

示例15: newTarOutputStream

 private TarOutputStream newTarOutputStream(string filename)
 {
     Stream oStream = File.Create(filename);
     //gzipStream = new BZip2OutputStream(oStream);
     GZipOutputStream gzipStream = new GZipOutputStream(oStream);
     gzipStream.SetLevel(3);
     return new TarOutputStream(gzipStream);
 }
开发者ID:411blue,项目名称:echo-backup,代码行数:8,代码来源:StorageThread.cs


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