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


C# Stream.Flush方法代码示例

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


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

示例1: ExtractFile

        /// <summary>
        /// Copy the contents of a stored file into an opened stream
        /// </summary>
        /// <param name="_zfe">Entry information of file to extract</param>
        /// <param name="_stream">Stream to store the uncompressed data</param>
        /// <returns>True if success, false if not.</returns>
        /// <remarks>Unique compression methods are Store and Deflate</remarks>
        public bool ExtractFile(ZipFileEntry _zfe, Stream _stream)
        {
            if (!_stream.CanWrite)
                 throw new InvalidOperationException("Stream cannot be written");

             // check signature
             byte[] signature = new byte[4];
             this.ZipFileStream.Seek(_zfe.HeaderOffset, SeekOrigin.Begin);
             this.ZipFileStream.Read(signature, 0, 4);
             if (BitConverter.ToUInt32(signature, 0) != 0x04034b50)
                 return false;

             // Select input stream for inflating or just reading
             Stream inStream;
             if (_zfe.Method == Compression.Store)
                 inStream = this.ZipFileStream;
             else if (_zfe.Method == Compression.Deflate)
                 inStream = new DeflateStream(this.ZipFileStream, CompressionMode.Decompress, true);
             else
                 return false;

             // Buffered copy
             byte[] buffer = new byte[16384];
             this.ZipFileStream.Seek(_zfe.FileOffset, SeekOrigin.Begin);
             uint bytesPending = _zfe.FileSize;
             while (bytesPending > 0)
             {
                 int bytesRead = inStream.Read(buffer, 0, (int)Math.Min(bytesPending, buffer.Length));
                 _stream.Write(buffer, 0, bytesRead);
                 bytesPending -= (uint)bytesRead;
             }
             _stream.Flush();

             if (_zfe.Method == Compression.Deflate)
                 inStream.Dispose();
             return true;
        }
开发者ID:aswartzbaugh,项目名称:biketour,代码行数:44,代码来源:ZipStorer.cs


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