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


C# ZlibStream.Flush方法代码示例

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


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

示例1: Comp

        public static byte[] Comp(byte[] input)
        {
            using (var sourceStream = new MemoryStream(input))
            {
                using (var compressed = new MemoryStream())
                {
                    using (var zipSteam = new ZlibStream(compressed, CompressionMode.Compress, CompressionLevel.Level9, true))
                    {
                        zipSteam.FlushMode = FlushType.Full;

                        //var buffer = new byte[1024];
                        //int len = sourceStream.Read(buffer, 0, buffer.Length);

                        //while (len > 0)
                        //{
                        //    zipSteam.Write(buffer, 0, len);
                        //    len = sourceStream.Read(buffer, 0, buffer.Length);
                        //}

                        sourceStream.CopyTo(zipSteam);

                        zipSteam.Flush();

                        return compressed.ToArray();
                    }
                }
            }
        }
开发者ID:Scrivener07,项目名称:moddingSuite,代码行数:28,代码来源:Compressing.cs

示例2: Compress

 /// <summary>
 /// Compress to CompressedData
 /// </summary>
 public static MemoryStream Compress(byte[] buffer)
 {
     var output = new MemoryStream();
     using (ZlibStream zout = new ZlibStream(output, CompressionMode.Compress))
     {
         zout.Write(buffer, 0, buffer.Length);
         zout.Flush();
     }
     return output;
 }
开发者ID:mctraveler,项目名称:MineSharp,代码行数:13,代码来源:Compression.cs

示例3: CompressChunk

        public byte[] CompressChunk()
        {
            //File and body headers ar emanaged outside

            //All we do here is to write the compressed tag

            using (MemoryStream ms = new MemoryStream())
            {
                using (ZlibStream compressed = new ZlibStream(ms, CompressionMode.Compress, true))
                {
                    var w = new EndianBinaryWriter(EndianBitConverter.Big, compressed);
                    Tag.Write(w);
                    compressed.Flush();
                }
                return ms.ToArray();
            }
        }
开发者ID:mctraveler,项目名称:MineSharp,代码行数:17,代码来源:McaChunk.cs

示例4: ZibDecompress

        public static byte[] ZibDecompress(byte[] data)
        {
            var ms = new MemoryStream(data);
            using (var msDecompressed = new System.IO.MemoryStream())
            {
                using (var zs = new ZlibStream(msDecompressed, CompressionMode.Decompress, true))
                {
                    int readByte = ms.ReadByte();
                    while (readByte != -1)
                    {
                        zs.WriteByte((byte)readByte);
                        readByte = ms.ReadByte();
                    }
                    zs.Flush();
                }
                return msDecompressed.ToArray();

            }
        }
开发者ID:RobertHu,项目名称:TraderServer,代码行数:19,代码来源:ZlibHelper.cs

示例5: Save

        public void Save(Stream stream)
        {
            long dataStart = CalculateDataStartOffset();

            stream.Seek(dataStart, SeekOrigin.Begin);

            long fileStart = 0;

            long compressedSize = 0;
            long uncompressedSize = 0;

            // Output file data
            ZlibStream dataStream = null;
            if (IsCompressed && IsCondensed)
            {
                dataStream = new ZlibStream(stream, CompressionMode.Compress, CompressionLevel.BestCompression, true);
                dataStream.FlushMode = FlushType.Sync;
            }

            long compressedStart = 0;

            for (int i = 0; i < Files.Count; i++)
            {
                IPackfileEntry entry = Files[i];
                Stream fs = m_Streams[entry.Name];

                bool isLast = (i == (Files.Count - 1));

                PackfileEntry pfE = (PackfileEntry)entry;
                var data = pfE.Data;
                data.Start = (uint)fileStart;
                data.Size = (uint)fs.Length;
                data.Alignment = (IsCondensed) ? (ushort)16 : (ushort)1;
                
                if (this.IsCompressed)
                    data.Flags = PackfileEntryFlags.Compressed;

                if (IsCompressed && IsCondensed)
                {
                    fs.CopyTo(dataStream);
                    dataStream.Flush();
                    long afterData = dataStream.TotalOut;
                    data.CompressedSize = (uint)(afterData - compressedStart);
                    compressedStart = afterData;

                    if (IsStr2)
                    {
                        fileStart += data.Size.Align(16);
                        uncompressedSize += data.Size.Align(16);
                        compressedSize += data.CompressedSize;
                    }
                    else
                    {
                        fileStart += data.Size; //.Align(16);
                        if (!isLast)
                        {
                            uncompressedSize += data.Size; //.Align(16);
                            //uint toSkip = data.Size.Align(16) - data.Size;
//                            for (int j = 0; j < toSkip; j++)
                                //dataStream.WriteByte(0);
                        }
                        else
                        {
                            uncompressedSize += data.Size;
                        }
                        compressedSize += data.CompressedSize;
                    }
                }
                else if (IsCondensed)
                {
                    fs.CopyTo(stream);
                    data.CompressedSize = 0xFFFFFFFF;

                    fileStart += data.Size.Align(16);

                    if (isLast)
                        uncompressedSize += data.Size;
                    else
                    {
                        uint toSkip = data.Size.Align(16) - data.Size;
                        uncompressedSize += data.Size.Align(16);
                        stream.Seek(toSkip, SeekOrigin.Current);
                    }

                }
                else if (IsCompressed)
                {
                    long beforeData = stream.Position;
                    using (dataStream = new ZlibStream(stream, CompressionMode.Compress, CompressionLevel.BestCompression, true))
                    {
                        dataStream.FlushMode = FlushType.Sync;
                        fs.CopyTo(dataStream);
                        dataStream.Flush();
                    }
                    long afterData = stream.Position;
                    data.CompressedSize = (uint)(afterData - beforeData);
                    fileStart += data.CompressedSize;
                    uncompressedSize += data.Size;
                    compressedSize += data.CompressedSize;
                }
//.........这里部分代码省略.........
开发者ID:rodrigonh,项目名称:ThomasJepp.SaintsRow,代码行数:101,代码来源:Packfile.cs

示例6: Compress

        private byte[] Compress(byte[] revlogEntryData, int offset, int count)
        {
            using(var memoryStream = new MemoryStream())
            {
                using(var zlibStream = new ZlibStream(memoryStream, CompressionMode.Compress))
                {
                    zlibStream.Write(revlogEntryData, offset, count);
                    zlibStream.Flush();
                } // using

                return memoryStream.ToArray();
            } // using
        }
开发者ID:cornelius90,项目名称:InnovatorAdmin,代码行数:13,代码来源:HgRevlogWriter.cs

示例7: writeToStreamOld

        private void writeToStreamOld(Stream s, bool le, bool readOnly)
        {
            bool compress = true;
            bool base64 = true;

            using (var tw = new StreamWriter(s, System.Text.Encoding.ASCII))
            {
                tw.NewLine = "\n";
                tw.WriteLine("Type: Floppy");

                if (readOnly)
                    tw.WriteLine("Access: Read-Only");
                else
                    tw.WriteLine("Access: Read-Write");

                if (le)
                    tw.WriteLine("Byte-Order: Little-Endian");
                else
                    tw.WriteLine("Byte-Order: Big-Endian");

                int lb = 0, hb = 1;
                if (!le)
                {
                    lb = 1;
                    hb = 0;
                }

                byte[] bytes, cbytes;

                bytes = new byte[1440 * 1024];
                for (int i = 0; i < _words.Length; ++i)
                {
                    var j = 2 * i;
                    bytes[j + lb] = (byte)_words[i];
                    bytes[j + hb] = (byte)(_words[i] >> 8);
                }

                if (compress)
                {
                    tw.WriteLine("Compression: Zlib");
                    using (var ms = new MemoryStream())
                    {
                        using (var cmpr = new ZlibStream(ms, CompressionMode.Compress, CompressionLevel.BestCompression, leaveOpen: true))
                        {
                            cmpr.Write(bytes, 0, bytes.Length);
                            cmpr.Flush();
                        }
                        cbytes = ms.ToArray();
                    }
                }
                else
                {
                    tw.WriteLine("Compression: None");
                    cbytes = bytes;
                }

                if (base64)
                {
                    var encoded = Convert.ToBase64String(cbytes, Base64FormattingOptions.InsertLineBreaks);

                    tw.WriteLine("Encoding: Base64");
                    tw.WriteLine("Content-Length: {0}", encoded.Length);
                    tw.WriteLine();
                    tw.WriteLine(encoded);
                }
                else
                {
                    tw.WriteLine("Encoding: None");
                    tw.WriteLine("Content-Length: {0}", cbytes.Length);
                    tw.WriteLine();
                    tw.Flush();
                    tw.BaseStream.Write(bytes, 0, cbytes.Length);
                }
            }
        }
开发者ID:DanielKeep,项目名称:0x10c,代码行数:75,代码来源:Disk.cs


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