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


C# ZipFileEntry类代码示例

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


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

示例1: AddStream

        /// <summary>
        ///     Add full contents of a stream into the Zip storage
        /// </summary>
        /// <param name="method">Compression method</param>
        /// <param name="filenameInZip">Filename and path as desired in Zip directory</param>
        /// <param name="source">Stream object containing the data to store in Zip</param>
        /// <param name="modTime">Modification time of the data to store</param>
        /// <param name="comment">Comment for stored file</param>
        public void AddStream(Compression method, string filenameInZip, Stream source, DateTime modTime, string comment)
        {
            if (_access == FileAccess.Read)
                throw new InvalidOperationException("Writing is not alowed");

            // Prepare the fileinfo
            var zfe = new ZipFileEntry
                {
                    Method = method,
                    EncodeUTF8 = EncodeUTF8,
                    FilenameInZip = NormalizedFilename(filenameInZip),
                    Comment = (comment ?? string.Empty),
                    Crc32 = 0,
                    HeaderOffset = (uint) _zipFileStream.Position,
                    ModifyTime = modTime
                };

            // Even though we write the header now, it will have to be rewritten, since we don't know compressed size or crc.

            // Write local header
            WriteLocalHeader(ref zfe);
            zfe.FileOffset = (uint) _zipFileStream.Position;

            // Write file to zip (store)
            Store(ref zfe, source);
            source.Close();

            UpdateCrcAndSizes(ref zfe);

            _files.Add(zfe);
        }
开发者ID:jpires,项目名称:gta2net,代码行数:39,代码来源:ZipStorer.cs

示例2: Store

        // Copies all source file into storage file
        private void Store(ref ZipFileEntry _zfe, Stream _source)
        {
            byte[] buffer = new byte[16384];
             int bytesRead;
             uint totalRead = 0;
             Stream outStream;

             long posStart = this.ZipFileStream.Position;
             long sourceStart = _source.Position;

             if (_zfe.Method == Compression.Store)
                 outStream = this.ZipFileStream;
             else
                 outStream = new DeflateStream(this.ZipFileStream, CompressionMode.Compress, true);

             _zfe.Crc32 = 0 ^ 0xffffffff;

             do
             {
                 bytesRead = _source.Read(buffer, 0, buffer.Length);
                 totalRead += (uint)bytesRead;
                 if (bytesRead > 0)
                 {
                     outStream.Write(buffer, 0, bytesRead);

                     for (uint i = 0; i < bytesRead; i++)
                     {
                         _zfe.Crc32 = ZipStorer.CrcTable[(_zfe.Crc32 ^ buffer[i]) & 0xFF] ^ (_zfe.Crc32 >> 8);
                     }
                 }
             } while (bytesRead == buffer.Length);
             outStream.Flush();

             if (_zfe.Method == Compression.Deflate)
                 outStream.Dispose();

             _zfe.Crc32 ^= 0xffffffff;
             _zfe.FileSize = totalRead;
             _zfe.CompressedSize = (uint)(this.ZipFileStream.Position - posStart);

             // Verify for real compression
             if (_zfe.Method == Compression.Deflate && !this.ForceDeflating && _source.CanSeek && _zfe.CompressedSize > _zfe.FileSize)
             {
                 // Start operation again with Store algorithm
                 _zfe.Method = Compression.Store;
                 this.ZipFileStream.Position = posStart;
                 this.ZipFileStream.SetLength(posStart);
                 _source.Position = sourceStart;
                 this.Store(ref _zfe, _source);
             }
        }
开发者ID:aswartzbaugh,项目名称:biketour,代码行数:52,代码来源:ZipStorer.cs

示例3: bytes

        /* Central directory's File header:
             central file header signature   4 bytes  (0x02014b50)
             version made by                 2 bytes
             version needed to extract       2 bytes
             general purpose bit flag        2 bytes
             compression method              2 bytes
             last mod file time              2 bytes
             last mod file date              2 bytes
             crc-32                          4 bytes
             compressed size                 4 bytes
             uncompressed size               4 bytes
             filename length                 2 bytes
             extra field length              2 bytes
             file comment length             2 bytes
             disk number start               2 bytes
             internal file attributes        2 bytes
             external file attributes        4 bytes
             relative offset of local header 4 bytes

             filename (variable size)
             extra field (variable size)
             file comment (variable size)
         */
        private void WriteCentralDirRecord(ZipFileEntry _zfe)
        {
            Encoding encoder = _zfe.EncodeUTF8 ? Encoding.UTF8 : DefaultEncoding;
             byte[] encodedFilename = encoder.GetBytes(_zfe.FilenameInZip);
             byte[] encodedComment = encoder.GetBytes(_zfe.Comment);

             this.ZipFileStream.Write(new byte[] { 80, 75, 1, 2, 23, 0xB, 20, 0 }, 0, 8);
             this.ZipFileStream.Write(BitConverter.GetBytes((ushort)(_zfe.EncodeUTF8 ? 0x0800 : 0)), 0, 2); // filename and comment encoding
             this.ZipFileStream.Write(BitConverter.GetBytes((ushort)_zfe.Method), 0, 2);  // zipping method
             this.ZipFileStream.Write(BitConverter.GetBytes(DateTimeToDosTime(_zfe.ModifyTime)), 0, 4);  // zipping date and time
             this.ZipFileStream.Write(BitConverter.GetBytes(_zfe.Crc32), 0, 4); // file CRC
             this.ZipFileStream.Write(BitConverter.GetBytes(_zfe.CompressedSize), 0, 4); // compressed file size
             this.ZipFileStream.Write(BitConverter.GetBytes(_zfe.FileSize), 0, 4); // uncompressed file size
             this.ZipFileStream.Write(BitConverter.GetBytes((ushort)encodedFilename.Length), 0, 2); // Filename in zip
             this.ZipFileStream.Write(BitConverter.GetBytes((ushort)0), 0, 2); // extra length
             this.ZipFileStream.Write(BitConverter.GetBytes((ushort)encodedComment.Length), 0, 2);

             this.ZipFileStream.Write(BitConverter.GetBytes((ushort)0), 0, 2); // disk=0
             this.ZipFileStream.Write(BitConverter.GetBytes((ushort)0), 0, 2); // file type: binary
             this.ZipFileStream.Write(BitConverter.GetBytes((ushort)0), 0, 2); // Internal file attributes
             this.ZipFileStream.Write(BitConverter.GetBytes((ushort)0x8100), 0, 2); // External file attributes (normal/readable)
             this.ZipFileStream.Write(BitConverter.GetBytes(_zfe.HeaderOffset), 0, 4);  // Offset of header

             this.ZipFileStream.Write(encodedFilename, 0, encodedFilename.Length);
             this.ZipFileStream.Write(encodedComment, 0, encodedComment.Length);
        }
开发者ID:aswartzbaugh,项目名称:biketour,代码行数:49,代码来源:ZipStorer.cs

示例4: AddStream

        /// <summary>
        /// Add full contents of a stream into the Zip storage
        /// </summary>
        /// <param name="_method">Compression method</param>
        /// <param name="_filenameInZip">Filename and path as desired in Zip directory</param>
        /// <param name="_source">Stream object containing the data to store in Zip</param>
        /// <param name="_modTime">Modification time of the data to store</param>
        /// <param name="_comment">Comment for stored file</param>
        public void AddStream(Compression _method, string _filenameInZip, Stream _source, DateTime _modTime, string _comment)
        {
            if (Access == FileAccess.Read)
                 throw new InvalidOperationException("Writing is not alowed");

             long offset;
             if (this.Files.Count == 0)
                 offset = 0;
             else
             {
                 ZipFileEntry last = this.Files[this.Files.Count - 1];
                 offset = last.HeaderOffset + last.HeaderSize;
             }

             // Prepare the fileinfo
             ZipFileEntry zfe = new ZipFileEntry();
             zfe.Method = _method;
             zfe.EncodeUTF8 = this.EncodeUTF8;
             zfe.FilenameInZip = NormalizedFilename(_filenameInZip);
             zfe.Comment = (_comment == null ? "" : _comment);

             // Even though we write the header now, it will have to be rewritten, since we don't know compressed size or crc.
             zfe.Crc32 = 0;  // to be updated later
             zfe.HeaderOffset = (uint)this.ZipFileStream.Position;  // offset within file of the start of this local record
             zfe.ModifyTime = _modTime;

             // Write local header
             WriteLocalHeader(ref zfe);
             zfe.FileOffset = (uint)this.ZipFileStream.Position;

             // Write file to zip (store)
             Store(ref zfe, _source);
             _source.Close();

             this.UpdateCrcAndSizes(ref zfe);

             Files.Add(zfe);
        }
开发者ID:aswartzbaugh,项目名称:biketour,代码行数:46,代码来源:ZipStorer.cs

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

示例6: UpdateCrcAndSizes

        private void UpdateCrcAndSizes(ref ZipFileEntry _zfe)
        {
            /* CRC32 algorithm
            The 'magic number' for the CRC is 0xdebb20e3.
            The proper CRC pre and post conditioning
            is used, meaning that the CRC register is
            pre-conditioned with all ones (a starting value
            of 0xffffffff) and the value is post-conditioned by
            taking the one's complement of the CRC residual.
            If bit 3 of the general purpose flag is set, this
            field is set to zero in the local header and the correct
            value is put in the data descriptor and in the central
            directory.
            */
            long lastPos = this.ZipFileStream.Position;

            this.ZipFileStream.Position = _zfe.HeaderOffset + 8;
            this.ZipFileStream.Write(BitConverter.GetBytes((ushort)_zfe.Method), 0, 2);

            this.ZipFileStream.Position = _zfe.HeaderOffset + 14;
            this.ZipFileStream.Write(BitConverter.GetBytes(_zfe.Crc32), 0, 4);
            this.ZipFileStream.Write(BitConverter.GetBytes(_zfe.CompressedSize), 0, 4);
            this.ZipFileStream.Write(BitConverter.GetBytes(_zfe.FileSize), 0, 4);

            this.ZipFileStream.Position = lastPos;
        }
开发者ID:joshaxey,项目名称:Redline,代码行数:26,代码来源:RedlineTest.cs

示例7: WriteLocalHeader

        private void WriteLocalHeader(ref ZipFileEntry _zfe)
        {
            /* Local file header:
            local file header signature     4 bytes  (0x04034b50)
            version needed to extract       2 bytes
            general purpose bit flag        2 bytes
            compression method              2 bytes
            last mod file time              2 bytes
            last mod file date              2 bytes
            crc-32                          4 bytes
            compressed size                 4 bytes
            uncompressed size               4 bytes
            filename length                 2 bytes
            extra field length              2 bytes

            filename (variable size)
            extra field (variable size)
            */
            long pos = this.ZipFileStream.Position;
            Encoding encoder = _zfe.EncodeUTF8 ? Encoding.UTF8 : DefaultEncoding;
            byte[] encodedFilename = encoder.GetBytes(_zfe.FilenameInZip);

            this.ZipFileStream.Write(new byte[] { 80, 75, 3, 4, 20, 0}, 0, 6);
            this.ZipFileStream.Write(BitConverter.GetBytes((ushort)(_zfe.EncodeUTF8 ? 0x0800 : 0)), 0, 2);
            this.ZipFileStream.Write(BitConverter.GetBytes((ushort)_zfe.Method), 0, 2);
            this.ZipFileStream.Write(BitConverter.GetBytes(DateTimeToDosTime(_zfe.ModifyTime)), 0, 4);
            this.ZipFileStream.Write(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 0, 12);
            this.ZipFileStream.Write(BitConverter.GetBytes((ushort)encodedFilename.Length), 0, 2);
            this.ZipFileStream.Write(BitConverter.GetBytes((ushort)0), 0, 2);

            this.ZipFileStream.Write(encodedFilename, 0, encodedFilename.Length);
            _zfe.HeaderSize = (uint)(this.ZipFileStream.Position - pos);
        }
开发者ID:joshaxey,项目名称:Redline,代码行数:33,代码来源:RedlineTest.cs

示例8: Store

        // Copies all source file into storage file
        private void Store(ref ZipFileEntry zfe, Stream source)
        {
            byte[] buffer = new byte[16384];
            int bytesRead;
            uint totalRead = 0;
            Stream outStream;
            long posStart = this.ZipFileStream.Position;

            if (zfe.Method == Compression.Store)
                outStream = this.ZipFileStream;
            else
                outStream = new DeflateStream(this.ZipFileStream, CompressionMode.Compress, true);

            zfe.Crc32 = 0 ^ 0xffffffff;

            do
            {
                bytesRead = source.Read(buffer, 0, buffer.Length);
                totalRead += (uint)bytesRead;
                if (bytesRead > 0)
                {
                    outStream.Write(buffer, 0, bytesRead);

                    for (uint i = 0; i < bytesRead; i++)
                    {
                        zfe.Crc32 = ZipStorer.CrcTable[(zfe.Crc32 ^ buffer[i]) & 0xFF] ^ (zfe.Crc32 >> 8);
                    }
                }
            } while (bytesRead == buffer.Length);
            outStream.Flush();

            if (zfe.Method == Compression.Deflate)
                outStream.Dispose();

            zfe.Crc32 ^= 0xffffffff;
            zfe.FileSize = totalRead;
            zfe.CompressedSize = (uint)(this.ZipFileStream.Position - posStart);
        }
开发者ID:mikoskinen,项目名称:SubtitleProvider,代码行数:39,代码来源:ZipStorer.cs

示例9: bytes

        /* Local file header:
            local file header signature     4 bytes  (0x04034b50)
            version needed to extract       2 bytes
            general purpose bit flag        2 bytes
            compression method              2 bytes
            last mod file time              2 bytes
            last mod file date              2 bytes
            crc-32                          4 bytes
            compressed size                 4 bytes
            uncompressed size               4 bytes
            filename length                 2 bytes
            extra field length              2 bytes

            filename (variable size)
            extra field (variable size)
        */
        private void WriteLocalHeader(ref ZipFileEntry zfe)
        {
            long pos = this.ZipFileStream.Position;
            byte[] encodedFilename = FilenameEncoder.GetBytes(zfe.FilenameInZip);

            this.ZipFileStream.Write(new byte[] { 80, 75, 3, 4, 20, 0, 0, 0 }, 0, 8); // No extra header
            this.ZipFileStream.Write(BitConverter.GetBytes((ushort)zfe.Method), 0, 2);  // zipping method
            this.ZipFileStream.Write(BitConverter.GetBytes(DosTime(zfe.ModifyTime)), 0, 4); // zipping date and time
            this.ZipFileStream.Write(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 0, 12); // unused CRC, un/compressed size, updated later
            this.ZipFileStream.Write(BitConverter.GetBytes((ushort)encodedFilename.Length), 0, 2); // filename length
            this.ZipFileStream.Write(BitConverter.GetBytes((ushort)0), 0, 2); // extra length

            this.ZipFileStream.Write(encodedFilename, 0, encodedFilename.Length);
            zfe.HeaderSize = (uint)(this.ZipFileStream.Position - pos);
        }
开发者ID:mikoskinen,项目名称:SubtitleProvider,代码行数:31,代码来源:ZipStorer.cs

示例10: ones

        /* CRC32 algorithm
          The 'magic number' for the CRC is 0xdebb20e3.
          The proper CRC pre and post conditioning
          is used, meaning that the CRC register is
          pre-conditioned with all ones (a starting value
          of 0xffffffff) and the value is post-conditioned by
          taking the one's complement of the CRC residual.
          If bit 3 of the general purpose flag is set, this
          field is set to zero in the local header and the correct
          value is put in the data descriptor and in the central
          directory.
        */
        private void UpdateCrcAndSizes(ref ZipFileEntry zfe)
        {
            var lastPos = _zipFileStream.Position; // remember position

            _zipFileStream.Position = zfe.HeaderOffset + 8;
            _zipFileStream.Write(BitConverter.GetBytes((ushort) zfe.Method), 0, 2); // zipping method

            _zipFileStream.Position = zfe.HeaderOffset + 14;
            _zipFileStream.Write(BitConverter.GetBytes(zfe.Crc32), 0, 4); // Update CRC
            _zipFileStream.Write(BitConverter.GetBytes(zfe.CompressedSize), 0, 4); // Compressed size
            _zipFileStream.Write(BitConverter.GetBytes(zfe.FileSize), 0, 4); // Uncompressed size

            _zipFileStream.Position = lastPos; // restore position
        }
开发者ID:jpires,项目名称:gta2net,代码行数:26,代码来源:ZipStorer.cs

示例11: ExtractStoredFile

        /// <summary>
        /// Copy the contents of a stored file into a physical file
        /// </summary>
        /// <param name="_zfe">Entry information of file to extract</param>
        /// <param name="_filename">Name of file to store uncompressed data</param>
        /// <returns>True if success, false if not.</returns>
        /// <remarks>Unique compression methods are Store and Deflate</remarks>
        public bool ExtractStoredFile(ZipFileEntry _zfe, string _filename)
        {
            // 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;

            // Make sure the parent directory exist
            string path = System.IO.Path.GetDirectoryName(_filename);
            if (!Directory.Exists(path))
                Directory.CreateDirectory(path);
            // Check it is directory. If so, do nothing
            if (Directory.Exists(_filename))
                return true;

            FileStream output = new FileStream(_filename, FileMode.Create, FileAccess.Write);

            // 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));
                output.Write(buffer, 0, bytesRead);
                bytesPending -= (uint)bytesRead;
            }
            output.Close();
            if (_zfe.Method == Compression.Deflate)
                inStream.Dispose();
            return true;
        }
开发者ID:mikoskinen,项目名称:SubtitleProvider,代码行数:50,代码来源:ZipStorer.cs

示例12: Store

        // Copies all source file into storage file
        private void Store(ref ZipFileEntry zfe, Stream source)
        {
            var buffer = new byte[16384];
            int bytesRead;
            uint totalRead = 0;

            var posStart = _zipFileStream.Position;
            var sourceStart = source.Position;

            Stream outStream = zfe.Method == Compression.Store ? _zipFileStream : new DeflateStream(_zipFileStream, CompressionMode.Compress, true);

            zfe.Crc32 = 0 ^ 0xffffffff;

            do
            {
                bytesRead = source.Read(buffer, 0, buffer.Length);
                totalRead += (uint) bytesRead;
                if (bytesRead <= 0)
                    continue;
                outStream.Write(buffer, 0, bytesRead);

                for (uint i = 0; i < bytesRead; i++)
                    zfe.Crc32 = CrcTable[(zfe.Crc32 ^ buffer[i]) & 0xFF] ^ (zfe.Crc32 >> 8);
            } while (bytesRead == buffer.Length);
            outStream.Flush();

            if (zfe.Method == Compression.Deflate)
                outStream.Dispose();

            zfe.Crc32 ^= 0xffffffff;
            zfe.FileSize = totalRead;
            zfe.CompressedSize = (uint) (_zipFileStream.Position - posStart);

            // Verify for real compression
            if (zfe.Method != Compression.Deflate || ForceDeflating || !source.CanSeek || zfe.CompressedSize <= zfe.FileSize)
                return;
            // Start operation again with Store algorithm
            zfe.Method = Compression.Store;
            _zipFileStream.Position = posStart;
            _zipFileStream.SetLength(posStart);
            source.Position = sourceStart;
            Store(ref zfe, source);
        }
开发者ID:jpires,项目名称:gta2net,代码行数:44,代码来源:ZipStorer.cs

示例13: ReadCentralDir

        /// <summary>
        ///     Read all the file records in the central directory
        /// </summary>
        /// <returns>List of all entries in directory</returns>
        public List<ZipFileEntry> ReadCentralDir()
        {
            if (_centralDirImage == null)
                throw new InvalidOperationException("Central directory currently does not exist");

            var result = new List<ZipFileEntry>();

            for (var pointer = 0; pointer < _centralDirImage.Length;)
            {
                var signature = BitConverter.ToUInt32(_centralDirImage, pointer);
                if (signature != 0x02014b50)
                    break;

                var encodeUTF8 = (BitConverter.ToUInt16(_centralDirImage, pointer + 8) & 0x0800) != 0;
                var method = BitConverter.ToUInt16(_centralDirImage, pointer + 10);
                var modifyTime = BitConverter.ToUInt32(_centralDirImage, pointer + 12);
                var crc32 = BitConverter.ToUInt32(_centralDirImage, pointer + 16);
                var comprSize = BitConverter.ToUInt32(_centralDirImage, pointer + 20);
                var fileSize = BitConverter.ToUInt32(_centralDirImage, pointer + 24);
                var filenameSize = BitConverter.ToUInt16(_centralDirImage, pointer + 28);
                var extraSize = BitConverter.ToUInt16(_centralDirImage, pointer + 30);
                var commentSize = BitConverter.ToUInt16(_centralDirImage, pointer + 32);
                var headerOffset = BitConverter.ToUInt32(_centralDirImage, pointer + 42);
                var headerSize = (uint) (46 + filenameSize + extraSize + commentSize);

                var encoder = encodeUTF8 ? Encoding.UTF8 : DefaultEncoding;

                var zfe = new ZipFileEntry
                    {
                        Method = (Compression) method,
                        FilenameInZip = encoder.GetString(_centralDirImage, pointer + 46, filenameSize),
                        FileOffset = GetFileOffset(headerOffset),
                        FileSize = fileSize,
                        CompressedSize = comprSize,
                        HeaderOffset = headerOffset,
                        HeaderSize = headerSize,
                        Crc32 = crc32,
                        ModifyTime = DosTimeToDateTime(modifyTime)
                    };
                if (commentSize > 0)
                    zfe.Comment = encoder.GetString(_centralDirImage, pointer + 46 + filenameSize + extraSize,
                                                    commentSize);

                result.Add(zfe);
                pointer += (46 + filenameSize + extraSize + commentSize);
            }

            return result;
        }
开发者ID:jpires,项目名称:gta2net,代码行数:53,代码来源:ZipStorer.cs

示例14: 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
            var signature = new byte[4];
            _zipFileStream.Seek(zfe.HeaderOffset, SeekOrigin.Begin);
            _zipFileStream.Read(signature, 0, 4);
            if (BitConverter.ToUInt32(signature, 0) != 0x04034b50)
                return false;

            // Select input stream for inflating or just reading
            Stream inStream;
            switch (zfe.Method)
            {
                case Compression.Store:
                    inStream = _zipFileStream;
                    break;
                case Compression.Deflate:
                    inStream = new DeflateStream(_zipFileStream, CompressionMode.Decompress, true);
                    break;
                default:
                    return false;
            }

            // Buffered copy
            var buffer = new byte[16384];
            _zipFileStream.Seek(zfe.FileOffset, SeekOrigin.Begin);
            var bytesPending = zfe.FileSize;
            while (bytesPending > 0)
            {
                var 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:jpires,项目名称:gta2net,代码行数:49,代码来源:ZipStorer.cs

示例15: ExtractFile

        /// <summary>
        /// Copy the contents of a stored file into a physical file.
        /// </summary>
        /// <param name="zipFileEntry">Entry information of file to extract.</param>
        /// <param name="destinationFileName">Name of file to store uncompressed data.</param>
        /// <returns><see langword="true"/> if the file is successfully extracted; otherwise, <see langword="false"/>.</returns>
        /// <remarks>Unique compression methods are Store and Deflate.</remarks>
        public bool ExtractFile(ZipFileEntry zipFileEntry, string destinationFileName)
        {
            // Make sure the parent directory exist
            string path = System.IO.Path.GetDirectoryName(destinationFileName);

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            // Check it is directory. If so, do nothing
            if (Directory.Exists(destinationFileName))
            {
                return true;
            }

            bool result = false;
            using (Stream output = new FileStream(destinationFileName, FileMode.Create, FileAccess.Write))
            {
                result = this.ExtractFile(zipFileEntry, output);
            }

            File.SetCreationTime(destinationFileName, zipFileEntry.ModifyTime);
            File.SetLastWriteTime(destinationFileName, zipFileEntry.ModifyTime);

            return result;
        }
开发者ID:Rameshnathan,项目名称:selenium,代码行数:34,代码来源:ZipStorer.cs


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