Example #1
0
        /// <summary>
        /// Creates a new Zip file entry reading values from a zip file
        /// </summary>
        internal ZipEntry(IntPtr handle)
        {
            var entryInfo = new ZipEntryInfo64();
            int result    = ZlibWrapper.ZlibUnzGetCurrentFileInfo64(handle, out entryInfo, null, 0, null, 0, null, 0);

            if (result != 0)
            {
                throw new ZipException($"Could not read entry from zip file \"{Name}\"", result);
            }

            byte[] extraField      = new byte[entryInfo.ExtraFieldLength];
            byte[] entryNameBuffer = new byte[entryInfo.FileNameLength];
            byte[] commentBuffer   = new byte[entryInfo.CommentLength];

            result = ZlibWrapper.ZlibUnzGetCurrentFileInfo64(handle, out entryInfo,
                                                             entryNameBuffer, (uint)entryNameBuffer.Length,
                                                             extraField, (uint)extraField.Length,
                                                             commentBuffer, (uint)commentBuffer.Length);

            if (result != 0)
            {
                throw new ZipException($"Could not read entry from zip file \"{Name}\"", result);
            }

            _utf8Encoding = (entryInfo.Flag & ZipEntryFlag.UTF8) == ZipEntryFlag.UTF8;
            Encoding encoding = _utf8Encoding ? Encoding.UTF8 : ZlibWrapper.OEMEncoding;

            Name = encoding.GetString(entryNameBuffer);
            UncompressedLength = (long)entryInfo.UncompressedSize;
            _fileAttributes    = (FileAttributes)entryInfo.ExternalFileAttributes;
            IsDirectory        = (_fileAttributes & FileAttributes.Directory) != 0;
        }
 public static extern int ZlibUnzGetCurrentFileInfo64(
     IntPtr handle,
     out ZipEntryInfo64 entryInfoPtr,
     byte[] entryNameBuffer,
     uint entryNameBufferLength,
     byte[] extraField,
     uint extraFieldLength,
     byte[] commentBuffer,
     uint commentBufferLength);