• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# ZipFileEntry类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: ExtractFile

 public bool ExtractFile(ZipFileEntry _zfe, string _filename)
 {
     return ExtractFile(_zfe, _filename, 0);
 }
开发者ID:Neal,项目名称:iKGD,代码行数:4,代码来源:ZipStorer.cs


示例17: AddStream

        /// <summary>
        /// 
        /// </summary>
        /// <param name="_method"></param>
        /// <param name="_filenameInZip"></param>
        /// <param name="_source"></param>
        /// <param name="_modTime"></param>
        /// <param name="_comment"></param>
        /// <exception cref="InvalidOperationException"></exception>
        public void AddStream(Compression _method, string _filenameInZip, Stream _source, DateTime _modTime, string _comment)
        {
            if (Access == FileAccess.Read)
                throw new InvalidOperationException("Writing is not allowed.");

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

            ZipFileEntry zfe = new ZipFileEntry();
            zfe.Method = _method;
            zfe.EncodeUTF8 = this.EncodeUTF8;
            zfe.FilenameInZip = NormalizedFilename(_filenameInZip);
            zfe.Comment = (_comment == null ? "" : _comment);
            zfe.Crc32 = 0;
            zfe.HeaderOffset = (uint)this.ZipFileStream.Position;
            zfe.ModifyTime = _modTime;

            WriteLocalHeader(ref zfe);
            zfe.FileOffset = (uint)this.ZipFileStream.Position;

            Store(ref zfe, _source);
            _source.Close();

            this.UpdateCrcAndSizes(ref zfe);

            Files.Add(zfe);
        }
开发者ID:joshaxey,项目名称:Redline,代码行数:42,代码来源:RedlineTest.cs


示例18: WriteCentralDirRecord

        private void WriteCentralDirRecord(ZipFileEntry _zfe)
        {
            /* 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)
            */
            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);
            this.ZipFileStream.Write(BitConverter.GetBytes((ushort)_zfe.Method), 0, 2);
            this.ZipFileStream.Write(BitConverter.GetBytes(DateTimeToDosTime(_zfe.ModifyTime)), 0, 4);
            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.Write(BitConverter.GetBytes((ushort)encodedFilename.Length), 0, 2);
            this.ZipFileStream.Write(BitConverter.GetBytes((ushort)0), 0, 2);
            this.ZipFileStream.Write(BitConverter.GetBytes((ushort)encodedComment.Length), 0, 2);
            this.ZipFileStream.Write(BitConverter.GetBytes((ushort)0), 0, 2);
            this.ZipFileStream.Write(BitConverter.GetBytes((ushort)0), 0, 2);
            this.ZipFileStream.Write(BitConverter.GetBytes((ushort)0), 0, 2);
            this.ZipFileStream.Write(BitConverter.GetBytes((ushort)0x8100), 0, 2);
            this.ZipFileStream.Write(BitConverter.GetBytes(_zfe.HeaderOffset), 0, 4);

            this.ZipFileStream.Write(encodedFilename, 0, encodedFilename.Length);
            this.ZipFileStream.Write(encodedComment, 0, encodedComment.Length);
        }
开发者ID:joshaxey,项目名称:Redline,代码行数:48,代码来源:RedlineTest.cs


示例19: AddStream

        /// <summary>
        /// Add full contents of a stream into the Zip storage
        /// </summary>
        /// <param name="method">Compression method</param>
        /// <param name="fileNameInZip">File name 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="fileComment">Comment for stored file</param>
        public void AddStream( Compression method, [NotNull] string fileNameInZip, [NotNull] Stream source,
                               DateTime modTime, [CanBeNull] string fileComment ) {
            if( fileNameInZip == null ) throw new ArgumentNullException( "fileNameInZip" );
            if( source == null ) throw new ArgumentNullException( "source" );
            if( access == FileAccess.Read )
                throw new InvalidOperationException( "Writing is not alowed" );

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

            // Prepare the fileinfo
            ZipFileEntry zfe = new ZipFileEntry {
                Method = method,
                EncodeUTF8 = EncodeUTF8,
                FileNameInZip = NormalizedFileName( fileNameInZip ),
                Comment = (fileComment ?? ""),
                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:fragmer,项目名称:fCraft,代码行数:48,代码来源:ZipStorer.cs


示例20: ZipStream

 /// <summary>
 /// Initializes a new instance of the <see cref="ZipStream"/> class.
 /// </summary>
 /// <param name="innerStream">
 /// The inner stream.
 /// </param>
 /// <param name="zipFileEntry">
 /// The zip file entry.
 /// </param>
 public ZipStream(Stream innerStream, ZipFileEntry zipFileEntry)
 {
     this.innerStream = innerStream;
     this.zipFileEntry = zipFileEntry;
 }
开发者ID:Anomalous-Software,项目名称:Android.Play.ExpansionLibrary,代码行数:14,代码来源:ZipStream.cs
<

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# ZipUpdate类代码示例发布时间:2022-05-24
下一篇:
C# ZipFile类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap