/// <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 ICSharpCode.SharpZipLib.Zip.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 ICSharpCode.SharpZipLib.GZip.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); }
private static Manifest ParseManifestStream(Stream secStream, FileEntry fileEntry, string password) { secStream.Seek(0, SeekOrigin.Begin); using (var zStream = GetDecryptStream(secStream, fileEntry, password)) { using (var gz = new ICSharpCode.SharpZipLib.GZip.GZipInputStream(zStream)) { var read = new MemoryStream(); var bytes = new byte[256]; do { var n = gz.Read(bytes, 0, bytes.Length); if (n <= 0) { break; } read.Write(bytes, 0, n); } while (true); var data = read.ToArray(); // Debug.LogFormat("read manifest data {0}", data.Length); var json = Encoding.UTF8.GetString(data); return(JsonUtility.FromJson <Manifest>(json)); } } }
public static byte[] Dekompresja(this System.IO.MemoryStream input) { if (input == null || input.Length == 0) { return(null); } var lBytes = new List <byte>(); using (var zip = new ICSharpCode.SharpZipLib.GZip.GZipInputStream(input)) { byte[] buffer = new byte[4096]; while (true) { int read = zip.Read(buffer, 0, buffer.Length); for (int i = 0; i < read; i++) { lBytes.Add(buffer[i]); } if (read <= 0) { break; } } } return(lBytes.ToArray()); }
public IEnumerable <string> LoadEntries() { byte[] buff = new byte[256]; using (var compressedStream = bucketStreamProvider.OpenRead(address)) { if (compressedStream == null || compressedStream.Length == 0) { yield break; } using (var zip = new ICSharpCode.SharpZipLib.GZip.GZipInputStream(compressedStream)) using (var breader = new BinaryReader(zip)) { var count = breader.ReadInt32(); for (int j = 0; j < count; ++j) { int cnt = breader.ReadInt32(); if (buff.Length < cnt) { buff = new byte[cnt + 1024]; } int readed = 0; while (readed != cnt) { readed += zip.Read(buff, readed, cnt - readed); } string message; message = Encoding.UTF8.GetString(buff, 0, cnt); yield return(message); } } } }
private void DecompresNowGZip() { int restan = 0; int size = 0; byte[] BytesDecompressed = new byte[50000]; this.m_streaminput.Seek(0, SeekOrigin.Begin); Stream s = new ICSharpCode.SharpZipLib.GZip.GZipInputStream(this.m_streaminput); try { while (true) { size = s.Read(BytesDecompressed, 0, (int)BytesDecompressed.Length); if (size > 0) { restan += size; size = restan; } else { break; } } } catch (ZipException e) { size = 0; Debug.WriteLine(e.Message); } finally { s.Read(BytesDecompressed, 0, restan); s.Flush(); this.m_streamoutput = null; this.m_streamoutput = new MemoryStream(restan); this.m_streamoutput.Write(BytesDecompressed, 0, restan); this.m_byteoutput = null; this.m_byteoutput = new byte[restan]; this.m_streamoutput.Seek(0, SeekOrigin.Begin); this.m_streamoutput.Read(this.m_byteoutput, 0, restan); this.m_streamoutput.Seek(0, SeekOrigin.Begin); //s.Close(); } }
/// <summary> /// 解压bytes /// </summary> /// <param name="param"></param> /// <returns></returns> public static byte[] DecompressBytes(byte[] buffer) { ICSharpCode.SharpZipLib.GZip.GZipInputStream gzp = new ICSharpCode.SharpZipLib.GZip.GZipInputStream(new MemoryStream(buffer)); MemoryStream re = new MemoryStream(); int count = 0; byte[] data = new byte[4096]; while ((count = gzp.Read(data, 0, data.Length)) != 0) { re.Write(data, 0, count); } return(re.ToArray()); }
static bool IsGzipFile(string filePath) { using (var fstm = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite, 64)) using (var stm = new ICSharpCode.SharpZipLib.GZip.GZipInputStream(fstm)) { try { stm.Read(new byte[0], 0, 0); return(true); } catch (ICSharpCode.SharpZipLib.GZip.GZipException) { return(false); } } }
/// <summary> /// 解压缩字节数组 /// 返回:已解压的字节数组 /// </summary> /// <param name="data">待解压缩的字节数组</param> /// <returns></returns> public static byte[] DecompressBytes(byte[] data) { var o = new MemoryStream(); var s = new ICSharpCode.SharpZipLib.GZip.GZipInputStream(new MemoryStream(data)); try { var size = 0; var buf = new byte[1024]; while ((size = s.Read(buf, 0, buf.Length)) > 0) { o.Write(buf, 0, size); } } finally { o.Close(); } return(o.ToArray()); }
/// <summary> /// Decompresses the specified string into the original string /// </summary> /// <param name="inputString">The compressed string</param> /// <returns>The decompressed version of the specified string</returns> public static string Decompress(string inputString) { // Create the zip stream System.IO.MemoryStream memstream = new System.IO.MemoryStream(Convert.FromBase64String(inputString)); ICSharpCode.SharpZipLib.GZip.GZipInputStream zipstream = new ICSharpCode.SharpZipLib.GZip.GZipInputStream(memstream); Byte[] readbuffer = new Byte[1024]; System.IO.MemoryStream writebuffer = new System.IO.MemoryStream(); int bytesread = 1; while (bytesread > 0) { bytesread = zipstream.Read(readbuffer, 0, readbuffer.Length); writebuffer.Write(readbuffer, 0, bytesread); } writebuffer.Close(); zipstream.Close(); memstream.Close(); return(System.Text.Encoding.Unicode.GetString(writebuffer.ToArray())); }
internal static byte[] Decompress(byte[] input) { int bufferSize = 2048; try { MemoryStream ms = new MemoryStream(input); MemoryStream ms1 = new MemoryStream(); ICSharpCode.SharpZipLib.GZip.GZipInputStream zipFile = new ICSharpCode.SharpZipLib.GZip.GZipInputStream(ms); byte[] output = new byte[2048]; while (bufferSize > 0) { bufferSize = zipFile.Read(output, 0, bufferSize); ms1.Write(output, 0, bufferSize); } ms1.Close(); return(ms1.ToArray()); } catch { return(null); } }
public override void ProcessCommand() { logger.Info("Processing CommandRequest_GetAniDBTitles"); try { bool process = ServerSettings.AniDB_Username.Equals("jonbaby", StringComparison.InvariantCultureIgnoreCase) || ServerSettings.AniDB_Username.Equals("jmediamanager", StringComparison.InvariantCultureIgnoreCase); if (!process) { return; } string url = Constants.AniDBTitlesURL; logger.Trace("Get AniDB Titles: {0}", url); Stream s = Utils.DownloadWebBinary(url); int bytes = 2048; byte[] data = new byte[2048]; StringBuilder b = new StringBuilder(); UTF8Encoding enc = new UTF8Encoding(); ICSharpCode.SharpZipLib.GZip.GZipInputStream zis = new ICSharpCode.SharpZipLib.GZip.GZipInputStream(s); while ((bytes = zis.Read(data, 0, data.Length)) > 0) { b.Append(enc.GetString(data, 0, bytes)); } zis.Close(); string[] lines = b.ToString().Split('\n'); Dictionary <int, AnimeIDTitle> titles = new Dictionary <int, AnimeIDTitle>(); foreach (string line in lines) { if (line.Trim().Length == 0 || line.Trim().Substring(0, 1) == "#") { continue; } string[] fields = line.Split('|'); int animeID = 0; int.TryParse(fields[0], out animeID); if (animeID == 0) { continue; } string titleType = fields[1].Trim().ToLower(); //string language = fields[2].Trim().ToLower(); string titleValue = fields[3].Trim(); AnimeIDTitle thisTitle = null; if (titles.ContainsKey(animeID)) { thisTitle = titles[animeID]; } else { thisTitle = new AnimeIDTitle(); thisTitle.AnimeIDTitleId = 0; thisTitle.MainTitle = titleValue; thisTitle.AnimeID = animeID; titles[animeID] = thisTitle; } if (!string.IsNullOrEmpty(thisTitle.Titles)) { thisTitle.Titles += "|"; } if (titleType.Equals("1")) { thisTitle.MainTitle = titleValue; } thisTitle.Titles += titleValue; } foreach (AnimeIDTitle aniTitle in titles.Values) { //AzureWebAPI.Send_AnimeTitle(aniTitle); CommandRequest_Azure_SendAnimeTitle cmdAzure = new CommandRequest_Azure_SendAnimeTitle(aniTitle.AnimeID, aniTitle.MainTitle, aniTitle.Titles); cmdAzure.Save(); } } catch (Exception ex) { logger.Error("Error processing CommandRequest_GetAniDBTitles: {0}", ex.ToString()); return; } }
private static FileStream UnzipToTempFile(string lpZipFile, string lpTempFile, ref GZipResult result) { FileStream fsIn = null; ICSharpCode.SharpZipLib.GZip.GZipInputStream gzip = null; FileStream fsOut = null; FileStream fsTemp = null; const int bufferSize = 4096; byte[] buffer = new byte[bufferSize]; int count = 0; try { fsIn = new FileStream(lpZipFile, FileMode.Open, FileAccess.Read, FileShare.Read); result.ZipFileSize = fsIn.Length; fsOut = new FileStream(lpTempFile, FileMode.Create, FileAccess.Write, FileShare.None); gzip = new ICSharpCode.SharpZipLib.GZip.GZipInputStream(fsIn); // gzip = new GZipStream(fsIn, CompressionMode.Decompress, true); while (true) { count = gzip.Read(buffer, 0, bufferSize); if (count != 0) { fsOut.Write(buffer, 0, count); } if (count != bufferSize) { break; } } } catch (System.Exception ex1) { //(Exception ex1) Debug.Log("UnzipToTempFile is Fail!!! " + ex1.ToString()); result.Errors = true; } finally { if (gzip != null) { gzip.Close(); gzip = null; } if (fsOut != null) { fsOut.Close(); fsOut = null; } if (fsIn != null) { fsIn.Close(); fsIn = null; } } fsTemp = new FileStream(lpTempFile, FileMode.Open, FileAccess.Read, FileShare.None); if (fsTemp != null) { result.TempFileSize = fsTemp.Length; } return(fsTemp); }
/// <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 ICSharpCode.SharpZipLib.Zip.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 ICSharpCode.SharpZipLib.GZip.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; }
public override void ProcessCommand() { logger.Info("Processing CommandRequest_GetAniDBTitles"); try { bool process = (ServerSettings.AniDB_Username.Equals("jonbaby", StringComparison.InvariantCultureIgnoreCase) || ServerSettings.AniDB_Username.Equals("jmediamanager", StringComparison.InvariantCultureIgnoreCase)); if (!process) return; string url = Constants.AniDBTitlesURL; logger.Trace("Get AniDB Titles: {0}", url); Stream s = Utils.DownloadWebBinary(url); int bytes = 2048; byte[] data = new byte[2048]; StringBuilder b = new StringBuilder(); UTF8Encoding enc = new UTF8Encoding(); ICSharpCode.SharpZipLib.GZip.GZipInputStream zis = new ICSharpCode.SharpZipLib.GZip.GZipInputStream(s); while ((bytes = zis.Read(data, 0, data.Length)) > 0) b.Append(enc.GetString(data, 0, bytes)); zis.Close(); AniDB_Anime_TitleRepository repTitles = new AniDB_Anime_TitleRepository(); string[] lines = b.ToString().Split('\n'); Dictionary<int, AnimeIDTitle> titles = new Dictionary<int, AnimeIDTitle>(); foreach (string line in lines) { if (line.Trim().Length == 0 || line.Trim().Substring(0, 1) == "#") continue; string[] fields = line.Split('|'); int animeID = 0; int.TryParse(fields[0], out animeID); if (animeID == 0) continue; string titleType = fields[1].Trim().ToLower(); //string language = fields[2].Trim().ToLower(); string titleValue = fields[3].Trim(); AnimeIDTitle thisTitle = null; if (titles.ContainsKey(animeID)) { thisTitle = titles[animeID]; } else { thisTitle = new AnimeIDTitle(); thisTitle.AnimeIDTitleId = 0; thisTitle.MainTitle = titleValue; thisTitle.AnimeID = animeID; titles[animeID] = thisTitle; } if (!string.IsNullOrEmpty(thisTitle.Titles)) thisTitle.Titles += "|"; if (titleType.Equals("1")) thisTitle.MainTitle = titleValue; thisTitle.Titles += titleValue; } foreach (AnimeIDTitle aniTitle in titles.Values) { //AzureWebAPI.Send_AnimeTitle(aniTitle); CommandRequest_Azure_SendAnimeTitle cmdAzure = new CommandRequest_Azure_SendAnimeTitle(aniTitle.AnimeID, aniTitle.MainTitle, aniTitle.Titles); cmdAzure.Save(); } } catch (Exception ex) { logger.Error("Error processing CommandRequest_GetAniDBTitles: {0}", ex.ToString()); return; } }