private static ZtPackage ExtractInternal(Stream stream, string fileName, string outputDir) { BinaryReader reader = new BinaryReader(stream); long startPosition = stream.Position; ZTENTRYHDR entryHdr = new ZTENTRYHDR(); ZTENTRY entry; List <ZTENTRYHDR> fileHdrs = new List <ZTENTRYHDR>(); List <ZTENTRY> fileEntries = new List <ZTENTRY>(); do { stream.Position = startPosition + entryHdr.OffsetNext; startPosition = stream.Position; entryHdr = reader.ReadUnmanaged <ZTENTRYHDR>(); entry = reader.ReadUnmanaged <ZTENTRY>(); fileHdrs.Add(entryHdr); fileEntries.Add(entry); if (outputDir != null) { byte[] fileData = Zlib.Decompress(reader, entry.CompressedLength, entry.DecompressedLength); /*byte[] compressed = reader.ReadBytes(entry.CompressedLength); * byte[] decompressed = new byte[entry.DecompressedLength]; * * Zlib.Uncompress(decompressed, ref entry.DecompressedLength, compressed, entry.CompressedLength);*/ File.WriteAllBytes(Path.Combine(outputDir, entry.FileName), fileData); } } while (entryHdr.OffsetNext != 0); return(new ZtPackage(fileName, fileHdrs.ToArray(), fileEntries.ToArray())); }
internal ZtEntry(ZTENTRYHDR hdr, ZTENTRY entry) { FileName = entry.FileName; Length = entry.DecompressedLength; }