public void Decompress(string filePath, string destFolder) { using (FileStream fs = File.OpenRead(filePath)) using (var gzs = new GZipStream(fs, CompressionMode.Decompress)) { var reader = new RawDataReader(gzs, Encoding.UTF8); foreach (byte b in Signature) { if (b != reader.ReadByte()) { throw new CorruptedFileException(filePath); } } int nbDir = reader.ReadInt(); var folders = new List <string>(nbDir); for (int i = 0; i < nbDir; ++i) { string dir = Path.Combine(destFolder, reader.ReadString()); folders.Add(dir); Directory.CreateDirectory(dir); } int nbFile = reader.ReadInt(); for (int i = 0; i < nbFile; ++i) { string file = reader.ReadString(); int ndxDir = reader.ReadInt(); if (ndxDir == NDX_CUR_FOLDER) { file = Path.Combine(destFolder, file); } else { file = Path.Combine(folders[ndxDir], file); } long fileLen = reader.ReadLong(); CreateFile(gzs, file, fileLen); FileDecompressed?.Invoke(file); } } }
public static IEnumerable <string> GetContent(string filePath) { using (FileStream fs = File.OpenRead(filePath)) using (var gzs = new GZipStream(fs, CompressionMode.Decompress)) { var reader = new RawDataReader(gzs, Encoding.UTF8); foreach (byte b in Signature) { if (b != reader.ReadByte()) { throw new CorruptedFileException(filePath); } } int nbDir = reader.ReadInt(); var folders = new List <string>(nbDir); for (int i = 0; i < nbDir; ++i) { string dir = reader.ReadString(); folders.Add(dir); } int nbFile = reader.ReadInt(); var files = new List <string>(nbFile); for (int i = 0; i < nbFile; ++i) { string file = reader.ReadString(); int ndxDir = reader.ReadInt(); if (ndxDir != NDX_CUR_FOLDER) { file = Path.Combine(folders[ndxDir], file); } files.Add(file); long fileLen = reader.ReadLong(); reader.Skip((int)fileLen); } return(files); } }