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


C# GZipStream.Write方法代码示例

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


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

示例1: 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 outStream = new MemoryStream(input.Length)) {
                using(var gzip = new GZipStream(outStream, CompressionMode.Compress)) {
                    gzip.Write(input, 0, input.Length);
                }
                output = outStream.ToArray();
            }

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

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

示例2: Compress

        /// <summary>
        /// Compresses the file at the given path. Returns the path to the
        /// compressed file.
        /// </summary>
        /// <param name="path">The path to compress.</param>
        /// <returns>The path of the compressed file.</returns>
        public string Compress(string path)
        {
            string outputPath = String.Concat(path, ".gz");

            if (File.Exists(outputPath))
            {
                File.Delete(outputPath);
            }

            using (FileStream fs = File.OpenRead(path))
            {
                using (FileStream output = File.Create(outputPath))
                {
                    using (GZipStream gzip = new GZipStream(output, CompressionMode.Compress, CompressionLevel.BestCompression))
                    {
                        byte[] buffer = new byte[4096];
                        int count = 0;

                        while (0 < (count = fs.Read(buffer, 0, buffer.Length)))
                        {
                            gzip.Write(buffer, 0, count);
                        }
                    }
                }
            }

            return outputPath;
        }
开发者ID:ChadBurggraf,项目名称:sthreeql,代码行数:34,代码来源:GZipCompressor.cs

示例3: compress

        static public byte[] compress(byte[] bytes)
        {

            var output = new MemoryStream();
            var gzipStream = new GZipStream(output, CompressionMode.Compress, true);
            gzipStream.Write(bytes, 0, bytes.Length);
            gzipStream.Close();
            return output.ToArray();

        }
开发者ID:superkaka,项目名称:LibForUnity,代码行数:10,代码来源:GZipCompresser.cs

示例4: Compress

 public static void Compress(byte[] data, string path)
 {
     using (GZipStream gzip = new GZipStream(
         new FileStream(path, FileMode.Create, FileAccess.Write),
         CompressionMode.Compress, CompressionLevel.BestCompression,
         false))
     {
         gzip.Write(data, 0, data.Length);
         gzip.Flush();
     }
 }
开发者ID:Ravenheart,项目名称:driversolutions,代码行数:11,代码来源:Tools.cs

示例5: CompressGzip

        public static byte[] CompressGzip(byte[] bytes)
        {
            using (var ms = new MemoryStream())
            {
                using (var zip = new GZipStream(ms, CompressionMode.Compress, true))
                {
                    zip.Write(bytes, 0, bytes.Length);
                }

                return ms.ToArray();
            }
        }
开发者ID:venusdharan,项目名称:Titanium-Web-Proxy,代码行数:12,代码来源:Compression.cs

示例6: CreateGZipStream

        /// <summary>Creates a GZip stream by the given serialized object.</summary>
        private static Stream CreateGZipStream(string serializedObject)
        {
            byte[] bytes = System.Text.Encoding.UTF8.GetBytes(serializedObject);
            using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
            {
                using (GZipStream gzip = new GZipStream(ms, CompressionMode.Compress, true))
                {
                    gzip.Write(bytes, 0, bytes.Length);
                }

                // Reset the stream to the beginning. It doesn't work otherwise!
                ms.Position = 0;
                byte[] compressed = new byte[ms.Length];
                ms.Read(compressed, 0, compressed.Length);
                return new MemoryStream(compressed);
            }
        }
开发者ID:Inspirony,项目名称:Emby.Plugins,代码行数:18,代码来源:HttpRequestMessageExtenstions.cs

示例7: GZipStreamTest

        public void GZipStreamTest()
        {
            string testString = "Some testing string to compress/decompress using the GzipStream object!";

            // compress.
            var testStringBytes = ASCIIEncoding.ASCII.GetBytes(testString);
            var compressedStream = new MemoryStream();
            var stream = new GZipStream(compressedStream, CompressionMode.Compress);
            stream.Write(testStringBytes, 0, testStringBytes.Length);
            stream.Flush();
            byte[] compressedTestString = compressedStream.ToArray();

            // decompress.
            compressedStream = new MemoryStream(compressedTestString);
            var decompressiongStream = new GZipStream(compressedStream, CompressionMode.Decompress);
            var decompressedStream = new MemoryStream();
            decompressiongStream.CopyTo(decompressedStream);
            var decompressedTestString = new byte[decompressedStream.Length];
            decompressedStream.Read(decompressedTestString, 0, decompressedTestString.Length);

            ASCIIEncoding.ASCII.GetString(decompressedTestString);
        }
开发者ID:UnifyKit,项目名称:OsmSharp,代码行数:22,代码来源:GZipStreamTests.cs

示例8: Compress

 private byte[] Compress(byte[] bytes)
 {
     if (this._compression.ToLower() == "gzip")
     {
         using (MemoryStream memory = new MemoryStream())
         {
             using (GZipStream gzip = new GZipStream(memory, CompressionMode.Compress, true))
             {
                 gzip.Write(bytes, 0, bytes.Length);
             }
             return memory.ToArray();
         }
     }
     if (this._compression.ToLower() == "deflate")
     {
         using (MemoryStream memory = new MemoryStream())
         {
             using (ZlibStream deflate = new ZlibStream(memory, CompressionMode.Compress, true))
             {
                 deflate.Write(bytes, 0, bytes.Length);
             }
             return memory.ToArray();
         }
     }
     //no compression
     return bytes;
 }
开发者ID:jbrwn,项目名称:tc,代码行数:27,代码来源:MapnikProvider.cs

示例9: CompressFile

    void CompressFile(string Source, string Destination)
    {
        Log(" Compressing " + Source);
        bool DeleteSource = false;

        if(  Source == Destination )
        {
            string CopyOrig = Source + ".Copy";
            File.Copy(Source, CopyOrig);
            Source = CopyOrig;
            DeleteSource = true;
        }

        using (System.IO.Stream input = System.IO.File.OpenRead(Source))
        {
            using (var raw = System.IO.File.Create(Destination))
                {
                    using (Stream compressor = new Ionic.Zlib.GZipStream(raw, Ionic.Zlib.CompressionMode.Compress,Ionic.Zlib.CompressionLevel.BestCompression))
                    {
                        byte[] buffer = new byte[2048];
                        int SizeRead = 0;
                        while ((SizeRead = input.Read(buffer, 0, buffer.Length)) != 0)
                        {
                            compressor.Write(buffer, 0, SizeRead);
                        }
                    }
                }
        }

        if (DeleteSource && File.Exists(Source))
        {
            File.Delete(Source);
        }
    }
开发者ID:colwalder,项目名称:unrealengine,代码行数:34,代码来源:HTML5Platform.Automation.cs

示例10: SaveMultiplayer

        public byte[] SaveMultiplayer(Player player)
        {
            //Save world to memory
            MemoryStream bytesStream = new MemoryStream();
            BinaryWriter bw = new BinaryWriter(bytesStream);

            //Basic world info
            SaveMultiplayer(bw);

            //Managers
            tileManager.Save(bw);
            itemManager.Save(bw);
            sectorManager.Save(bw);
            dayCycleManager.Save(bw);

            //Player avatar
            bw.Write(player.objectId);
            player.Save(bw);

            bw.Flush();

            byte[] bytes = bytesStream.ToArray();

            //Write header
            MemoryStream bytesStreamFinal = new MemoryStream();
            BinaryWriter bwFinal = new BinaryWriter(bytesStreamFinal);

            bwFinal.Write(bytes.Length);
            bwFinal.Flush();

            //Compress and write world
            GZipStream gzipStream = new GZipStream(bytesStreamFinal, CompressionMode.Compress, CompressionLevel.BestSpeed, true);
            gzipStream.Write(bytes, 0, bytes.Length);
            gzipStream.Close();

            return bytesStreamFinal.ToArray();
        }
开发者ID:carriercomm,项目名称:CubeWorld,代码行数:37,代码来源:CubeWorld.cs

示例11: Compress

 /// <summary>
 /// Compresses a byte array using the specified compression type.
 /// </summary>
 /// <param name="bytes">The byte array to be compressed.</param>
 /// <param name="level">Amount of compression to use.</param>
 /// <param name="type">Type of compression to use.</param>
 /// <returns>Compressed byte array.</returns>
 public static byte[] Compress(this byte[] bytes, CompressionLevel level, CompressionType type)
 {
     using (MemoryStream memory = new MemoryStream())
     {
         switch (type) {
             case CompressionType.Zlib:
                 using (ZlibStream stream = new ZlibStream(memory, CompressionMode.Compress, level, true))
                     stream.Write(bytes, 0, bytes.Length);
                 break;
             case CompressionType.GZip:
                 using (GZipStream stream = new GZipStream(memory, CompressionMode.Compress, level, true))
                     stream.Write(bytes, 0, bytes.Length);
                 break;
             default:
                 throw new ArgumentException("Unknown compression type.");
         }
         memory.Position = 0;
         bytes = new byte[memory.Length];
         memory.Read(bytes, 0, (int)memory.Length);
     }
     return bytes;
 }
开发者ID:Shade2010,项目名称:ForgeCraft,代码行数:29,代码来源:Extensions.cs

示例12: Zlib_GZipStream_FileName_And_Comments

        public void Zlib_GZipStream_FileName_And_Comments()
        {
            // select the name of the zip file
            string FileToCompress = System.IO.Path.Combine(TopLevelDir, "Zlib_GZipStream.dat");
            Assert.IsFalse(System.IO.File.Exists(FileToCompress), "The temporary zip file '{0}' already exists.", FileToCompress);
            byte[] working = new byte[WORKING_BUFFER_SIZE];
            int n = -1;

            int sz = this.rnd.Next(21000) + 15000;
            TestContext.WriteLine("  Creating file: {0} sz({1})", FileToCompress, sz);
            CreateAndFillFileText(FileToCompress, sz);

            System.IO.FileInfo fi1 = new System.IO.FileInfo(FileToCompress);
            int crc1 = DoCrc(FileToCompress);

            // four trials, all combos of FileName and Comment null or not null.
            for (int k = 0; k < 4; k++)
            {
                string CompressedFile = String.Format("{0}-{1}.compressed", FileToCompress, k);

                using (Stream input = File.OpenRead(FileToCompress))
                {
                    using (FileStream raw = new FileStream(CompressedFile, FileMode.Create))
                    {
                        using (GZipStream compressor =
                               new GZipStream(raw, CompressionMode.Compress, CompressionLevel.BestCompression, true))
                        {
                            // FileName is optional metadata in the GZip bytestream
                            if (k % 2 == 1)
                                compressor.FileName = FileToCompress;

                            // Comment is optional metadata in the GZip bytestream
                            if (k > 2)
                                compressor.Comment = "Compressing: " + FileToCompress;

                            byte[] buffer = new byte[1024];
                            n = -1;
                            while (n != 0)
                            {
                                if (n > 0)
                                    compressor.Write(buffer, 0, n);

                                n = input.Read(buffer, 0, buffer.Length);
                            }
                        }
                    }
                }

                System.IO.FileInfo fi2 = new System.IO.FileInfo(CompressedFile);

                Assert.IsTrue(fi1.Length > fi2.Length, String.Format("Compressed File is not smaller, trial {0} ({1}!>{2})", k, fi1.Length, fi2.Length));


                // decompress twice:
                // once with System.IO.Compression.GZipStream and once with Ionic.Zlib.GZipStream
                for (int j = 0; j < 2; j++)
                {
                    using (var input = System.IO.File.OpenRead(CompressedFile))
                    {

                        Stream decompressor = null;
                        try
                        {
                            switch (j)
                            {
                                case 0:
                                    decompressor = new Ionic.Zlib.GZipStream(input, CompressionMode.Decompress, true);
                                    break;
                                case 1:
                                    decompressor = new System.IO.Compression.GZipStream(input, System.IO.Compression.CompressionMode.Decompress, true);
                                    break;
                            }

                            string DecompressedFile =
                                                        String.Format("{0}.{1}.decompressed", CompressedFile, (j == 0) ? "Ionic" : "BCL");

                            TestContext.WriteLine("........{0} ...", System.IO.Path.GetFileName(DecompressedFile));

                            using (var s2 = System.IO.File.Create(DecompressedFile))
                            {
                                n = -1;
                                while (n != 0)
                                {
                                    n = decompressor.Read(working, 0, working.Length);
                                    if (n > 0)
                                        s2.Write(working, 0, n);
                                }
                            }

                            int crc2 = DoCrc(DecompressedFile);
                            Assert.AreEqual<Int32>(crc1, crc2);

                        }
                        finally
                        {
                            if (decompressor != null)
                                decompressor.Dispose();
                        }
                    }
                }
//.........这里部分代码省略.........
开发者ID:bedashii,项目名称:ReturnMedz,代码行数:101,代码来源:ZlibUnitTest1.cs

示例13: MakeApiCall

        public void MakeApiCall(CallRequestContainer reqContainer)
        {
            //Set headers
            var headers = new Dictionary<string, string> { { "Content-Type", "application/json" } };
            if (reqContainer.AuthKey == AuthType.DevSecretKey)
            {
#if ENABLE_PLAYFABSERVER_API || ENABLE_PLAYFABADMIN_API
                headers.Add("X-SecretKey", PlayFabSettings.DeveloperSecretKey);
#endif
            }
            else if (reqContainer.AuthKey == AuthType.LoginSession)
            {
                headers.Add("X-Authorization", AuthKey);
            }

            headers.Add("X-ReportErrorAsSuccess", "true");
            headers.Add("X-PlayFabSDK", PlayFabSettings.VersionString);

#if !UNITY_WSA && !UNITY_WP8 && !UNITY_WEBGL
            if (PlayFabSettings.CompressApiData)
            {
                headers.Add("Content-Encoding", "GZIP");
                headers.Add("Accept-Encoding", "GZIP");

                using (var stream = new MemoryStream())
                {
                    using (GZipStream zipstream = new GZipStream(stream, CompressionMode.Compress, CompressionLevel.BestCompression))
                    {
                        zipstream.Write(reqContainer.Payload, 0, reqContainer.Payload.Length);
                    }
                    reqContainer.Payload = stream.ToArray();
                }
            }
#endif

            //Debug.LogFormat("Posting {0} to Url: {1}", req.Trim(), url);
            var www = new WWW(reqContainer.FullUrl, reqContainer.Payload, headers);

#if PLAYFAB_REQUEST_TIMING
            var stopwatch = System.Diagnostics.Stopwatch.StartNew();
#endif

            // Start the www corouting to Post, and get a response or error which is then passed to the callbacks.
            Action<string> wwwSuccessCallback = (response) =>
            {
                try
                {
#if PLAYFAB_REQUEST_TIMING
                    var startTime = DateTime.UtcNow;
#endif
                    var httpResult = JsonWrapper.DeserializeObject<HttpResponseObject>(response, PlayFabUtil.ApiSerializerStrategy);

                    if (httpResult.code == 200)
                    {
                        // We have a good response from the server
                        reqContainer.JsonResponse = JsonWrapper.SerializeObject(httpResult.data, PlayFabUtil.ApiSerializerStrategy);
                        reqContainer.DeserializeResultJson();
                        reqContainer.ApiResult.Request = reqContainer.ApiRequest;
                        reqContainer.ApiResult.CustomData = reqContainer.CustomData;

#if !DISABLE_PLAYFABCLIENT_API
                        ClientModels.UserSettings userSettings = null;
                        var res = reqContainer.ApiResult as ClientModels.LoginResult;
                        var regRes = reqContainer.ApiResult as ClientModels.RegisterPlayFabUserResult;
                        if (res != null)
                        {
                            userSettings = res.SettingsForUser;
                            AuthKey = res.SessionTicket;
                        }
                        else if (regRes != null)
                        {
                            userSettings = regRes.SettingsForUser;
                            AuthKey = regRes.SessionTicket;
                        }

                        if (userSettings != null && AuthKey != null && userSettings.NeedsAttribution)
                        {
                            PlayFabIdfa.OnPlayFabLogin();
                        }

                        var cloudScriptUrl = reqContainer.ApiResult as ClientModels.GetCloudScriptUrlResult;
                        if (cloudScriptUrl != null)
                        {
                            PlayFabSettings.LogicServerUrl = cloudScriptUrl.Url;
                        }
#endif
                        try
                        {
                            PlayFabHttp.SendEvent(reqContainer.ApiRequest, reqContainer.ApiResult, ApiProcessingEventType.Post);
                        }
                        catch (Exception e)
                        {
                            Debug.LogException(e);
                        }

#if PLAYFAB_REQUEST_TIMING
                        stopwatch.Stop();
                        var timing = new PlayFabHttp.RequestTiming {
                            StartTimeUtc = startTime,
                            ApiEndpoint = reqContainer.ApiEndpoint,
//.........这里部分代码省略.........
开发者ID:codermoon,项目名称:RetroRun,代码行数:101,代码来源:PlayFabWWW.cs

示例14: PublishFile

        /// <summary>
        /// Publishes a file to Amazon S3.
        /// </summary>
        /// <param name="filePath">The path of the file to publish.</param>
        private void PublishFile(string filePath)
        {
            NameValueCollection headers = new NameValueCollection();
            string contentType = MimeType.FromCommon(filePath).ContentType;
            string objectKey = this.ObjectKey(filePath);

            if (this.OverwriteExisting || !this.ObjectExists(objectKey))
            {
                PutObjectRequest request = new PutObjectRequest()
                    .WithBucketName(this.BucketName)
                    .WithCannedACL(S3CannedACL.PublicRead)
                    .WithContentType(contentType)
                    .WithKey(objectKey)
                    .WithTimeout(this.Timeout);

                bool gzip = false;
                string tempPath = null;

                if (contentType.StartsWith("text", StringComparison.OrdinalIgnoreCase))
                {
                    gzip = true;
                    tempPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), Path.GetRandomFileName());

                    using (FileStream fs = File.OpenRead(filePath))
                    {
                        using (FileStream temp = File.Create(tempPath))
                        {
                            using (GZipStream gz = new GZipStream(temp, CompressionMode.Compress))
                            {
                                byte[] buffer = new byte[4096];
                                int count;

                                while (0 < (count = fs.Read(buffer, 0, buffer.Length)))
                                {
                                    gz.Write(buffer, 0, count);
                                }
                            }
                        }
                    }

                    headers["Content-Encoding"] = "gzip";
                    request = request.WithFilePath(tempPath);
                }
                else
                {
                    request = request.WithFilePath(filePath);
                }

                request.AddHeaders(headers);

                using (PutObjectResponse response = this.Client().PutObject(request))
                {
                }

                if (!String.IsNullOrEmpty(tempPath) && File.Exists(tempPath))
                {
                    File.Delete(tempPath);
                }

                this.PublisherDelegate.OnFilePublished(filePath, objectKey, gzip);
            }
            else
            {
                this.PublisherDelegate.OnFileSkipped(filePath, objectKey);
            }
        }
开发者ID:ChadBurggraf,项目名称:tasty,代码行数:70,代码来源:S3Publisher.cs

示例15: Save

        public byte[] Save()
        {
			//Save world to memory
			MemoryStream bytesStream = new MemoryStream();
			BinaryWriter bw = new BinaryWriter(bytesStream);
			
            Save(bw, false);
            tileManager.Save(bw);
            itemManager.Save(bw);
            avatarManager.Save(bw);
            sectorManager.Save(bw);
            dayCycleManager.Save(bw);

            bw.Flush();
			
			byte[] bytes = bytesStream.ToArray();
			
			//Write header
            MemoryStream bytesStreamFinal = new MemoryStream();
            BinaryWriter bwFinal = new BinaryWriter(bytesStreamFinal);

            bwFinal.Write(VERSION_INFO);
			bwFinal.Write(bytes.Length);
			bwFinal.Flush();
			
			//Compress and write world
			GZipStream gzipStream = new GZipStream(bytesStreamFinal, CompressionMode.Compress, CompressionLevel.BestSpeed, true);
			gzipStream.Write(bytes, 0, bytes.Length);
			gzipStream.Close();

            return bytesStreamFinal.ToArray();
        }
开发者ID:carriercomm,项目名称:CubeWorld,代码行数:32,代码来源:CubeWorld.cs


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