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());
                    }
        }