private void ReadMimeType(ZipEntry entry) { using (var ms = new MemoryStream()) { _zipInputStream.CopyTo(ms); _mimeType = Encoding.GetString(ms.ToArray()); } }
public IEnumerable <byte[]> ReadFilesFromArchive(string packageFilePath, IEnumerable <string> filesToGet) { CheckPackageExists(packageFilePath); var files = new HashSet <string>(filesToGet.Select(f => f.ToLower())); using (var fs = File.OpenRead(packageFilePath)) { using (var zipInputStream = new ZipInputStream(fs)) { ZipEntry zipEntry; while ((zipEntry = zipInputStream.GetNextEntry()) != null) { if (zipEntry.IsDirectory) { continue; } if (files.Contains(zipEntry.Name)) { using (var memStream = new MemoryStream()) { zipInputStream.CopyTo(memStream); yield return(memStream.ToArray()); memStream.Close(); } } } zipInputStream.Close(); } fs.Close(); } }
/// <summary> /// zip解压 /// </summary> /// <param name="sourceFile"></param> public static void DeCompress(string zipFile, string toDirectory) { if (!File.Exists(zipFile)) { throw new ArgumentException("要解压的文件不存在"); } //var path = Directory.GetParent(sourceFile).FullName; //var root = Path.GetDirectoryName(zipFile); //var fileName = Path.GetFileNameWithoutExtension(zipFile); using (var inputStream = new ZipInputStream(File.OpenRead(zipFile))) { while (true) { var zipNextEntry = inputStream.GetNextEntry(); if (zipNextEntry == null) { break; } if (!Directory.Exists(toDirectory)) { Directory.CreateDirectory(toDirectory);//创建解压到的文件夹 } var file = Path.Combine(toDirectory, zipNextEntry.Name); using (var streamWriter = File.Create(file)) { inputStream.CopyTo(streamWriter); } } } }
/// <summary> /// Initializes a new instance of the <see cref="LazyArtifact"/> class. /// </summary> /// <param name="entry">The entry.</param> /// <param name="inputStream">The input stream.</param> internal LazyArtifact(ZipEntry entry, ZipInputStream inputStream) { if (entry.Size > MaxSizeInMemory) { var fileName = Path.GetTempPath() + Guid.NewGuid() + ".tmp"; dataStream = new FileStream( fileName, FileMode.CreateNew, FileAccess.ReadWrite, FileShare.None, 4096, // The default buffer size is 4096. FileOptions.DeleteOnClose); } else { dataStream = new MemoryStream(); } inputStream.CopyTo(dataStream); dataStream.Seek(0, SeekOrigin.Begin); Name = entry.Name; }
public void MakeFilesInZipUnixExecutable(AbsolutePath zipFile) { var tmpFileName = zipFile + ".tmp"; using (var input = new ZipInputStream(File.Open(zipFile, FileMode.Open))) using (var output = new ZipOutputStream(File.Open(tmpFileName, FileMode.Create))) { output.SetLevel(9); ZipEntry entry; while ((entry = input.GetNextEntry()) != null) { var outEntry = new ZipEntry(entry.Name) { HostSystem = (int)HostSystemID.Unix }; var entryAttributes = ZipEntryAttributes.ReadOwner | ZipEntryAttributes.ReadOther | ZipEntryAttributes.ReadGroup | ZipEntryAttributes.ExecuteOwner | ZipEntryAttributes.ExecuteOther | ZipEntryAttributes.ExecuteGroup; entryAttributes = entryAttributes | (entry.IsDirectory ? ZipEntryAttributes.Directory : ZipEntryAttributes.Regular); outEntry.ExternalFileAttributes = (int)(entryAttributes) << 16; // https://unix.stackexchange.com/questions/14705/the-zip-formats-external-file-attribute output.PutNextEntry(outEntry); input.CopyTo(output); } output.Finish(); output.Flush(); } DeleteFile(zipFile); RenameFile(tmpFileName, zipFile, FileExistsPolicy.Overwrite); }
public static void UnzipFiles(string zipFile, string outDir) { using (var s = new ZipInputStream(File.OpenRead(zipFile))) { ZipEntry entry; while ((entry = s.GetNextEntry()) != null) { string outPath = Path.Combine(outDir, entry.Name); string directoryName = Path.GetDirectoryName(outPath); string fileName = Path.GetFileName(outPath); if (!string.IsNullOrWhiteSpace(directoryName)) { Directory.CreateDirectory(directoryName); } if (!string.IsNullOrWhiteSpace(fileName)) { using (FileStream outFile = File.Create(outPath)) { s.CopyTo(outFile); } } } } }
public void Unzip(string path) { using (var fs = File.OpenRead(ZipPath)) using (var s = new ZipInputStream(fs)) { long length = fs.Length; ZipEntry e; while ((e = s.GetNextEntry()) != null) { var zfile = Path.Combine(path, e.Name); var dirName = Path.GetDirectoryName(zfile); var fileName = Path.GetFileName(zfile); if (!string.IsNullOrWhiteSpace(dirName)) { Directory.CreateDirectory(dirName); } if (!string.IsNullOrWhiteSpace(fileName)) { using (var zFileStream = File.OpenWrite(zfile)) { s.CopyTo(zFileStream); } } //Console.WriteLine(zfile); ev(s.Position, length); } } }
/// <summary> /// unzip plugin contents to the given directory. /// </summary> /// <param name="zipFile">The path to the zip file.</param> /// <param name="strDirectory">The output directory.</param> /// <param name="overWrite">overwirte</param> private static void UnZip(string zipFile, string strDirectory, bool overWrite) { if (strDirectory == "") { strDirectory = Directory.GetCurrentDirectory(); } using (ZipInputStream zipStream = new ZipInputStream(File.OpenRead(zipFile))) { ZipEntry theEntry; while ((theEntry = zipStream.GetNextEntry()) != null) { var pathToZip = theEntry.Name; var directoryName = String.IsNullOrEmpty(pathToZip) ? "" : Path.GetDirectoryName(pathToZip); var fileName = Path.GetFileName(pathToZip); var destinationDir = Path.Combine(strDirectory, directoryName); var destinationFile = Path.Combine(destinationDir, fileName); Directory.CreateDirectory(destinationDir); if (String.IsNullOrEmpty(fileName) || (File.Exists(destinationFile) && !overWrite)) { continue; } using (FileStream streamWriter = File.Create(destinationFile)) { zipStream.CopyTo(streamWriter); } } } }
public static List <byte[]> UnZipFileToByte(Stream inputStream, string password = "") { List <byte[]> fileData = new List <byte[]>(); using (ZipInputStream s = new ZipInputStream(inputStream)) { if (!string.IsNullOrEmpty(password)) { s.Password = password; //Zip压缩文件密码 } ZipEntry theEntry; while ((theEntry = s.GetNextEntry()) != null) { if (theEntry.Name != String.Empty) { using (MemoryStream ms = new MemoryStream()) { s.CopyTo(ms); fileData.Add(ms.ToArray()); } } } } return(fileData); }
/// <summary> /// Decompresses the given data stream from its source ZIP or GZIP format. /// </summary> /// <param name="dataBytes"></param> /// <returns></returns> private static byte[] Inflate(byte[] dataBytes) { byte[] outputBytes = null; var zipInputStream = new ZipInputStream(new MemoryStream(dataBytes)); if (zipInputStream.CanDecompressEntry) { MemoryStream zipoutStream = new MemoryStream(); #if XBOX byte[] buf = new byte[4096]; int amt = -1; while (true) { amt = zipInputStream.Read(buf, 0, buf.Length); if (amt == -1) { break; } zipoutStream.Write(buf, 0, amt); } #else zipInputStream.CopyTo(zipoutStream); #endif outputBytes = zipoutStream.ToArray(); } else { try { var gzipInputStream = new GZipInputStream(new MemoryStream(dataBytes)); MemoryStream zipoutStream = new MemoryStream(); #if XBOX byte[] buf = new byte[4096]; int amt = -1; while (true) { amt = gzipInputStream.Read(buf, 0, buf.Length); if (amt == -1) { break; } zipoutStream.Write(buf, 0, amt); } #else gzipInputStream.CopyTo(zipoutStream); #endif outputBytes = zipoutStream.ToArray(); } catch (Exception exc) { CCLog.Log("Error decompressing image data: " + exc.Message); } } return(outputBytes); }
/// <summary> /// Decompresses the given data stream from its source ZIP or GZIP format. /// </summary> /// <param name="dataBytes"></param> /// <returns></returns> internal static byte[] Inflate(Stream dataStream) { byte[] outputBytes = null; var zipInputStream = new ZipInputStream(dataStream); if (zipInputStream.CanDecompressEntry) { MemoryStream zipoutStream = new MemoryStream(); zipInputStream.CopyTo(zipoutStream); outputBytes = zipoutStream.ToArray(); } else { try { dataStream.Seek(0, SeekOrigin.Begin); #if !WINDOWS_PHONE var gzipInputStream = new GZipInputStream(dataStream, CompressionMode.Decompress); #else var gzipInputStream = new GZipInputStream(dataStream); #endif MemoryStream zipoutStream = new MemoryStream(); gzipInputStream.CopyTo(zipoutStream); outputBytes = zipoutStream.ToArray(); } catch (Exception exc) { CCLog.Log("Error decompressing image data: " + exc.Message); } } return(outputBytes); }
public static void MakeFilesInZipUnixExecutable(AbsolutePath zipFile) { var tmpFileName = zipFile + ".tmp"; using (var input = new ZipInputStream(File.Open(zipFile, FileMode.Open))) using (var output = new ZipOutputStream(File.Open(tmpFileName, FileMode.Create))) { output.SetLevel(9); ZipEntry entry; while ((entry = input.GetNextEntry()) != null) { var outEntry = new ZipEntry(entry.Name); outEntry.HostSystem = (int)HostSystemID.Unix; outEntry.ExternalFileAttributes = -2115174400; output.PutNextEntry(outEntry); input.CopyTo(output); } output.Finish(); output.Flush(); } DeleteFile(zipFile); RenameFile(tmpFileName, zipFile, FileExistsPolicy.Overwrite); }
void ReadFile(string path, XmlNode node) { if (!File.Exists(path)) { return; } foreach (var n in Util.GetChildNodes(node, "Extract")) { var toFolder = Program.Shared.ReplaceTags(Util.GetStr(n, "toFolder")); var counter = 0; using (var fs = new FileStream(path, FileMode.Open, FileAccess.Read)) using (var zipStream = new ZipInputStream(fs)){ var entry = zipStream.GetNextEntry(); while (entry != null) { var file = Path.Combine(toFolder, entry.Name); var folder = Path.GetDirectoryName(file); if (!Directory.Exists(folder)) { Directory.CreateDirectory(folder); } using (var newFs = File.Create(file)) zipStream.CopyTo(newFs); entry = zipStream.GetNextEntry(); counter++; } } Program.Shared.WriteLogLine("Zip file extracted to folder {0} (Files: {1})", toFolder, counter); } }
public void MakeFilesInZipUnixExecutable(AbsolutePath zipFile) { var tmpFileName = zipFile + ".tmp"; using (var input = new ZipInputStream(File.Open(zipFile, FileMode.Open))) using (var output = new ZipOutputStream(File.Open(tmpFileName, FileMode.Create))) { output.SetLevel(9); ZipEntry entry; while ((entry = input.GetNextEntry()) != null) { var outEntry = new ZipEntry(entry.Name); outEntry.HostSystem = (int)HostSystemID.Unix; var entryAttributes = ZipEntryAttributes.ReadOwner | ZipEntryAttributes.ReadOther | ZipEntryAttributes.ReadGroup; // if (LifecycleHooks.Any(hook => entry.Name.EndsWith(hook))) entryAttributes = entryAttributes | ZipEntryAttributes.ExecuteOwner | ZipEntryAttributes.ExecuteOther | ZipEntryAttributes.ExecuteGroup; entryAttributes = entryAttributes | (entry.IsDirectory ? ZipEntryAttributes.Directory : ZipEntryAttributes.Regular); // outEntry.ExternalFileAttributes = -2115174400; outEntry.ExternalFileAttributes = (int)(entryAttributes) << 16; output.PutNextEntry(outEntry); input.CopyTo(output); } output.Finish(); output.Flush(); } DeleteFile(zipFile); RenameFile(tmpFileName, zipFile, FileExistsPolicy.Overwrite); }
private Tuple <JToken, JToken> extractInstaller(Stream stream, string extractPath) { // extract installer string install_profile = null; string versions_json = null; using (stream) using (var s = new ZipInputStream(stream)) { ZipEntry e; while ((e = s.GetNextEntry()) != null) { if (e.Name.Length <= 0) { continue; } var realpath = Path.Combine(extractPath, e.Name); if (e.IsFile) { if (e.Name == "install_profile.json") { install_profile = readStreamString(s); } else if (e.Name == "version.json") { versions_json = readStreamString(s); } else { Directory.CreateDirectory(Path.GetDirectoryName(realpath)); using (var fs = File.OpenWrite(realpath)) s.CopyTo(fs); } } } } JToken profileObj; var installObj = JObject.Parse(install_profile); // installer info var versionInfo = installObj["versionInfo"]; // version profile if (versionInfo == null) { profileObj = JObject.Parse(versions_json); } else { installObj = installObj["install"] as JObject; profileObj = versionInfo; } return(new Tuple <JToken, JToken>(profileObj, installObj)); }
private static void UnZipFiles(string zipPathAndFile, string outputFolder, bool deleteZipFile) { try { if (outputFolder != "") { Directory.CreateDirectory(outputFolder); } using (var zipFileStream = File.OpenRead(zipPathAndFile)) using (var zipInputStream = new ZipInputStream(zipFileStream)) { while (true) { var entry = zipInputStream.GetNextEntry(); if (entry is null) { break; } var fileName = Path.GetFileName(entry.Name); if (fileName == string.Empty || entry.Name.Contains(".ini")) { continue; } var fullPath = Path.Combine(outputFolder, entry.Name).Replace("\\ ", "\\"); var fullDirPath = Path.GetDirectoryName(fullPath); if (fullDirPath is not null && !Directory.Exists(fullDirPath)) { Directory.CreateDirectory(fullDirPath); } using (var fileStream = File.Create(fullPath)) { zipInputStream.CopyTo(fileStream); } } } if (deleteZipFile) { File.Delete(zipPathAndFile); } } catch (Exception e) { MessageBox.Show(e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
protected override void _Rollback() { try { if (_Files.Count > 0) { using (FileStream fs = File.Open(OutputFile, FileMode.Open, FileAccess.Read, FileShare.None)) { using (ZipInputStream zStream = new ZipInputStream(fs)) { zStream.IsStreamOwner = false; ZipEntry e = null; while ((e = zStream.GetNextEntry()) != null) { try { string file = _Files[e.Name]; if (!File.Exists(file)) { if (!Directory.Exists(STEM.Sys.IO.Path.GetDirectoryName(file))) { Directory.CreateDirectory(STEM.Sys.IO.Path.GetDirectoryName(file)); } using (FileStream s = File.Open(file, FileMode.CreateNew, FileAccess.ReadWrite, FileShare.None)) { zStream.CopyTo(s); } File.SetLastWriteTimeUtc(file, e.DateTime); } } catch { } } } } if (File.Exists(OutputFile)) { File.Delete(OutputFile); } } } catch (Exception ex) { AppendToMessage(ex.ToString()); Exceptions.Add(ex); } }
static void Main(string[] args) { int i; StreamWriter sw = new StreamWriter("output-html.txt"); WebClient wcList = new WebClient(); byte[] dataTop = wcList.DownloadData("https://covid19radar-jpn-prod.azureedge.net/c19r/440/list.json"); String jsonText = Encoding.ASCII.GetString(dataTop); List <JsonDataFormat> listR = JsonSerializer.Deserialize <List <JsonDataFormat> >(jsonText); int k; for (k = 0; k < listR.Count; k++) { JsonDataFormat df = listR[k]; WebClient wc = new WebClient(); byte[] dataBin = wc.DownloadData(df.url); MemoryStream inputStream = new MemoryStream(dataBin); MemoryStream outputStream = new MemoryStream(); ZipInputStream zipInputStream = new ZipInputStream(inputStream); zipInputStream.GetNextEntry(); zipInputStream.CopyTo(outputStream); byte[] dataOut = outputStream.ToArray(); TemporaryExposureKeyExport teke; // 先頭16バイトのヘッダを読み捨てる byte[] dataOut3 = new byte[dataOut.Length - 16]; for (i = 0; i < dataOut3.Length; i++) { dataOut3[i] = dataOut[i + 16]; } // Parserに入力する teke = TemporaryExposureKeyExport.Parser.ParseFrom(dataOut3); SHA256 mySHA = SHA256.Create(); byte[] hashValue = mySHA.ComputeHash(dataOut); sw.Write("<li>"); for (i = 0; i < hashValue.Length; i++) { sw.Write("{0:X2}", hashValue[i]); } var jstTimeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById("Tokyo Standard Time"); DateTime epochStart = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); epochStart = epochStart.AddSeconds((double)teke.StartTimestamp); DateTime jstStart = System.TimeZoneInfo.ConvertTimeFromUtc(epochStart, jstTimeZoneInfo); DateTime epochEnd = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); epochEnd = epochEnd.AddSeconds((double)teke.EndTimestamp); DateTime jstEnd = System.TimeZoneInfo.ConvertTimeFromUtc(epochEnd, jstTimeZoneInfo); sw.WriteLine(" at " + jstStart.ToString() + " - " + jstEnd.ToString() + "</li>"); } sw.Close(); }
public void Load(string filePath) { if (!File.Exists(filePath)) { throw new FileNotFoundException(filePath); } using var stream = new FileStream(filePath, FileMode.Open); using var zip = new ZipInputStream(stream); zip.GetNextEntry(); memStream = new MemoryStream(); zip.CopyTo(memStream); memStream.Position = 0; }
private byte[] GetUncompressedPayload(byte[] data) { using (MemoryStream memoryStream = new MemoryStream()) { using (MemoryStream baseInputStream = new MemoryStream(data)) { using (ZipInputStream zipInputStream = new ZipInputStream(baseInputStream)) { zipInputStream.GetNextEntry(); zipInputStream.CopyTo(memoryStream); } return(memoryStream.ToArray()); } } }
public static ZipContainer Unzip(Stream stream) { ZipEntry entry; var zippedFiles = new List <ZippedFile>(); var source = new ZipInputStream(stream); while ((entry = source.GetNextEntry()) != null) { if (entry.IsFile) { var destination = new MemoryStream(); source.CopyTo(destination); zippedFiles.Add(new ZippedFile(destination, entry.Name.Replace('\\', '/'))); } } return(new ZipContainer(zippedFiles)); }
// unzip all entries of the given file to the directory it resides in. public static void Unzip(string zipFile) { string targetDir = Path.GetDirectoryName(zipFile); using (var zipStream = new ZipInputStream(File.OpenRead(zipFile))) { ZipEntry entry = zipStream.GetNextEntry(); int tryCount = 0; while (entry != null) { try { if (DontUnzip.Contains(entry.Name)) { Console.WriteLine("Skipping {0}", entry.Name); entry = zipStream.GetNextEntry(); continue; } string targetFile = Path.Combine(targetDir, entry.Name); using (FileStream outStream = File.Create(targetFile)) { zipStream.CopyTo(outStream); } // give specific notes to user // (like "AutoUpdater has been updated but can't be installed automatically, unzip manually") if (entry.Name.Equals("README")) { foreach (string line in File.ReadAllLines(targetFile)) { Console.WriteLine(line); } } entry = zipStream.GetNextEntry(); } catch { if (tryCount++ < 5) { Console.WriteLine("Could not unpack {0}; retrying", entry.Name); } else { Console.WriteLine("Giving up. It's probably best if you manually extract that file.", entry.Name); tryCount = 0; entry = zipStream.GetNextEntry(); } } } } }
/// <summary> /// 只能解压压缩文件中的文件 /// </summary> /// <param name="path">解压到文件路径</param> /// <param name="zipFilePath">要解压的压缩文件路径</param> static void UnZipFile(string path, string zipFilePath) { using (ZipInputStream u = new ZipInputStream(File.OpenRead(zipFilePath))) { u.Password = "******"; ZipEntry ze = null; while ((ze = u.GetNextEntry()) != null) { string filePath = path + "\\" + ze.Name; if (ze.IsFile) { using (FileStream fs = new FileStream(filePath, FileMode.OpenOrCreate)) { u.CopyTo(fs); } } } } }
// part of a folder <- ZIP stream /// <summary> /// Unzips the specified ZIP stream to the new or existing folder. If the folder already exists, archive items will be added to the existing folder structure. /// Files will be overwritten when there is an existing file with the same name as an archive file. /// </summary> public static void UnZipStreamIntoFolder(Stream sourceStream, string destinationFolderPath) { Directory.CreateDirectory(destinationFolderPath); using (var zipInputStream = new ZipInputStream(sourceStream)) { ZipEntry entry; while ((entry = zipInputStream.GetNextEntry()) != null) { if (entry.IsDirectory) { Directory.CreateDirectory(EwlStatics.CombinePaths(destinationFolderPath, entry.Name)); } else { using (var outputStream = IoMethods.GetFileStreamForWrite(EwlStatics.CombinePaths(destinationFolderPath, entry.Name))) zipInputStream.CopyTo(outputStream); } } } }
public Zip(Stream stream) { Files = new Dictionary <FileName, byte[]>(); using (var zip = new ZipInputStream(stream)) { ZipEntry e; while ((e = zip.GetNextEntry()) != null) { if (e.IsFile) { using (var ms = new MemoryStream()) { zip.CopyTo(ms); Files[e.Name] = ms.ToArray(); } } } } }
public List <AuDefinition> GetResourceList() { List <AuDefinition> AuDefinitionList = new List <AuDefinition>(); HttpClient downloader = new HttpClient(); Stream stream = null; stream = downloader.GetStreamAsync(definitionUrl).Result; using (ZipInputStream s = new ZipInputStream(stream)) { ZipEntry entry; while ((entry = s.GetNextEntry()) != null) { if (entry.Name.EndsWith(".xml", StringComparison.CurrentCultureIgnoreCase)) { //Console.WriteLine($"Modified: {entry.DateTime.ToShortDateString()} {entry.DateTime.ToShortTimeString()}"); if (entry.IsFile) { var buffer = new MemoryStream(); s.CopyTo(buffer); buffer.Seek(0, SeekOrigin.Begin); var sr = SerializationUtil.XmlReaderFromStream(buffer); Resource resource = new Hl7.Fhir.Serialization.FhirXmlParser().Parse <Resource>(sr); AuDefinition AuDef = new AuDefinition(); AuDef.FileName = entry.Name; AuDef.FhirId = resource.Id; AuDef.ResourceType = resource.ResourceType; AuDef.Resource = resource; AuDefinitionList.Add(AuDef); Console.WriteLine("Resource File Name : {0}", entry.Name); } } } // Close can be ommitted as the using statement will do it automatically // but leaving it here reminds you that is should be done. s.Close(); } return(AuDefinitionList); }
/// <summary> /// Decompress a single file from a zip archive passed as Stream /// </summary> /// <param name="compressedStream"></param> /// <param name="fileName"></param> /// <returns></returns> public static MemoryStream DecompressInMemory(Stream compressedStream, string fileName) { MemoryStream resultStream = new MemoryStream(); using (var zipStream = new ZipInputStream(compressedStream)) { ZipEntry file = zipStream.GetNextEntry(); while (file != null) { if (fileName == file.FileName) { zipStream.CopyTo(resultStream); resultStream.Position = 0; break; } } } return(resultStream); }
/// <summary> /// This method completely ignores directory structure of the zip file in the source stream. The result is a flattened list of files. But, the file names do contain /// the relative path information, so they can be used to re-create the directory structure. /// </summary> public static IEnumerable <RsFile> UnZipStreamAsFileObjects(Stream source) { var files = new List <RsFile>(); using (var zipInputStream = new ZipInputStream(source)) { ZipEntry entry; while ((entry = zipInputStream.GetNextEntry()) != null) { if (entry.IsDirectory) { continue; } using (var outputStream = new MemoryStream()) { zipInputStream.CopyTo(outputStream); files.Add(new RsFile(outputStream.ToArray(), entry.Name)); } } } return(files); }
public override Stream OpenRead(string fileName) { MemoryStream ms = null; using (Stream stream = FileInfo.OpenRead()) using (ZipInputStream zis = new ZipInputStream(stream)) { ZipEntry entry; while ((entry = zis.GetNextEntry()) != null) { if (entry.IsFile && string.Equals(entry.Name, fileName, StringComparison.InvariantCultureIgnoreCase)) { ms = new MemoryStream((int)entry.Size); zis.CopyTo(ms, (int)entry.Size); ms.Seek(0, SeekOrigin.Begin); break; } } } return ms; }
public static string Unzip(this byte[] content) { byte[] buffer; using (MemoryStream ms = new MemoryStream(content)) { ms.Seek(0, SeekOrigin.Begin); using (ZipInputStream str = new ZipInputStream(ms, (int)ms.Length)) { str.IsStreamOwner = false; str.GetNextEntry(); using (MemoryStream stream = new MemoryStream()) { str.CopyTo(stream); buffer = new byte[stream.Length]; buffer = stream.ToArray(); } } } return(Encoding.UTF8.GetString(buffer, 0, buffer.Length)); }