Esempio n. 1
0
        public Byte[] Extract(CentralDirectoryFileHeader header)
        {
            var local = new LocalFileHeader(header.Bytes, header.RelativeOffsetOfLocalFileHeader);
            var pos   = local.Offset + local.Length;

            var dst = new Byte[local.UncompressedSize];

#if true
            using (var s = new MemoryStream(header.Bytes, pos, local.CompressedSize, false))
                using (var deflateStream = new DeflateStream(s, CompressionMode.Decompress))
                {
                    int dst_pos = 0;
                    for (int remain = dst.Length; remain > 0;)
                    {
                        var readSize = deflateStream.Read(dst, dst_pos, remain);
                        dst_pos += readSize;
                        remain  -= readSize;
                    }
                }
#else
            var size = RawInflate.RawInflateImport.RawInflate(dst, 0, dst.Length,
                                                              header.Bytes, pos, header.CompressedSize);
#endif

            return(dst);
        }
Esempio n. 2
0
        public string ExtractToString(CentralDirectoryFileHeader header, Encoding encoding)
        {
            var local = new LocalFileHeader(header.Bytes, header.RelativeOffsetOfLocalFileHeader);
            var pos   = local.Offset + local.Length;

            using (var s = new MemoryStream(header.Bytes, pos, local.CompressedSize, false))
                using (var deflateStream = new DeflateStream(s, CompressionMode.Decompress))
                    using (var r = new StreamReader(deflateStream, encoding))
                    {
                        return(r.ReadToEnd());
                    }
        }
Esempio n. 3
0
        public static ZipArchiveStorage Parse(byte[] bytes)
        {
            var eocd    = EOCD.Parse(bytes);
            var archive = new ZipArchiveStorage();

            var pos = eocd.OffsetOfStartOfCentralDirectory;

            for (int i = 0; i < eocd.NumberOfCentralDirectoryRecordsOnThisDisk; ++i)
            {
                var file = new CentralDirectoryFileHeader(bytes, pos);
                archive.Entries.Add(file);
                pos += file.Length;
            }

            return(archive);
        }