/// <summary> /// 解压 /// </summary> /// <param name="param"></param> /// <returns></returns> public static string Deompress(string param) { Debug.Log("11111111111111commonString:"); string commonString = ""; int data = 0; int stopByte = -1; byte[] buffer = Convert.FromBase64String(param);// 解base64 MemoryStream intms = new MemoryStream(buffer); zlib.ZInputStream inZStream = new zlib.ZInputStream(intms); int count = 1024 * 1024; byte[] inByteList = new byte[count]; int i = 0; while (stopByte != (data = inZStream.Read())) { inByteList[i] = (byte)data; i++; } inZStream.Close(); commonString = System.Text.Encoding.UTF8.GetString(inByteList, 0, inByteList.Length); Debug.Log(commonString); Debug.Log("22222222222222commonString:"); return(commonString); }
public static byte[] Uncompress(Stream input, int uncompressedSize) { byte[] buff = new byte[uncompressedSize]; ZInputStream reader = new ZInputStream(input); reader.EnsureRead(buff, 0, uncompressedSize); return buff; }
public static void UnpackSng(Stream input, Stream output, Platform platform) { EndianBitConverter conv; switch (platform.platform) { case GamePlatform.Pc: case GamePlatform.Mac: // Desktop conv = EndianBitConverter.Little; break; case GamePlatform.XBox360: case GamePlatform.PS3: // Console conv = EndianBitConverter.Big; break; default: conv = EndianBitConverter.Little; break; } using (var decrypted = new MemoryStream()) using (var br = new EndianBinaryReader(conv, input)) using (var brDec = new EndianBinaryReader(conv, decrypted)) { byte[] key; switch (platform.platform) { case GamePlatform.Mac: key = RijndaelEncryptor.SngKeyMac; break; default: //PC key = RijndaelEncryptor.SngKeyPC; break; } RijndaelEncryptor.DecryptSngData(br.BaseStream, decrypted, key); //unZip int bSize = 1; uint zLen = brDec.ReadUInt32(); ushort xU = brDec.ReadUInt16(); brDec.BaseStream.Position -= 2; if (xU == 55928)//LE 55928 //BE 30938 { var z = new zlib.ZInputStream(brDec.BaseStream); do { byte[] buf = new byte[bSize]; z.read(buf, 0, bSize); output.Write(buf, 0, bSize); } while (output.Length < (long)zLen); z.Close(); } } }
public static void Uncompress(Stream input, Stream output, int uncompressedSize, byte[] buff, CancellationToken cancelationToken, Action<long> uncompressed = null) { Exceptions.CheckArgumentNull(input, "input"); Exceptions.CheckArgumentNull(output, "output"); Exceptions.CheckArgumentOutOfRangeException(uncompressedSize, "uncompressedSize", 0, int.MaxValue); ZInputStream reader = new ZInputStream(input); int readed; while (uncompressedSize > 0 && (readed = reader.read(buff, 0, Math.Min(buff.Length, uncompressedSize))) > 0) { if (cancelationToken.IsCancellationRequested) return; uncompressedSize -= readed; output.Write(buff, 0, readed); uncompressed.NullSafeInvoke(readed); } if (uncompressedSize != 0) throw new Exception("Неожиданный конец потока."); }
public static byte[] DecompressData(byte[] inData) { int data = 0; int stopByte = -1; byte[] Buffer = inData; // 解base64 MemoryStream intms = new MemoryStream(Buffer); zlib.ZInputStream inZStream = new zlib.ZInputStream(intms); int count = 1024 * 1024; byte[] inByteList = new byte[count]; int i = 0; while (stopByte != (data = inZStream.Read())) { inByteList[i] = (byte)data; i++; } inZStream.Close(); return(inByteList.Take(i).ToArray()); }
public override int Read(byte[] buffer, int offset, int count) { if (buffer == null) throw new ArgumentNullException("buffer", Resources.BufferCannotBeNull); if (offset < 0 || offset >= buffer.Length) throw new ArgumentOutOfRangeException("offset", Resources.OffsetMustBeValid); if ((offset + count) > buffer.Length) throw new ArgumentException(Resources.BufferNotLargeEnough, "buffer"); if (inPos == maxInPos) PrepareNextPacket(); int countToRead = Math.Min(count, maxInPos - inPos); int countRead; if (zInStream != null) countRead = zInStream.read(buffer, offset, countToRead); else countRead = baseStream.Read(buffer, offset, countToRead); inPos += countRead; // release the weak reference if (inPos == maxInPos) { zInStream = null; inBufferRef.Target = inBuffer; inBuffer = null; } return countRead; }
private void PrepareNextPacket() { // read off the uncompressed and compressed lengths byte b1 = (byte) baseStream.ReadByte(); byte b2 = (byte) baseStream.ReadByte(); byte b3 = (byte) baseStream.ReadByte(); int compressedLength = b1 + (b2 << 8) + (b3 << 16); baseStream.ReadByte(); // seq int unCompressedLength = baseStream.ReadByte() + (baseStream.ReadByte() << 8) + (baseStream.ReadByte() << 16); if (unCompressedLength == 0) { unCompressedLength = compressedLength; zInStream = null; } else { ReadNextPacket(compressedLength); MemoryStream ms = new MemoryStream(inBuffer); zInStream = new ZInputStream(ms); zInStream.maxInput = compressedLength; } inPos = 0; maxInPos = unCompressedLength; }
private void PrepareNextPacket() { MySqlStream.ReadFully(baseStream, lengthBytes, 0, 7); int compressedLength = lengthBytes[0] + (lengthBytes[1] << 8) + (lengthBytes[2] << 16); // lengthBytes[3] is seq int unCompressedLength = lengthBytes[4] + (lengthBytes[5] << 8) + (lengthBytes[6] << 16); if (unCompressedLength == 0) { unCompressedLength = compressedLength; zInStream = null; } else { ReadNextPacket(compressedLength); MemoryStream ms = new MemoryStream(inBuffer); zInStream = new ZInputStream(ms); zInStream.maxInput = compressedLength; } inPos = 0; maxInPos = unCompressedLength; }
/// <summary> /// Unpacks zipped data. /// </summary> /// <param name="str">In Stream.</param> /// <param name="outStream">Out stream.</param> /// <param name = "plainLen">Data size after decompress.</param> /// <param name = "rewind">Manual control for stream seek position.</param> public static void Unzip(Stream str, Stream outStream, bool rewind = true) { int len; var buffer = new byte[65536]; var zOutputStream = new ZInputStream(str); while ((len = zOutputStream.read(buffer, 0, buffer.Length)) > 0) { outStream.Write(buffer, 0, len); } zOutputStream.Close(); buffer = null; if (rewind) { outStream.Position = 0; outStream.Flush(); } }
/// <summary> /// 解压Deflate数据至 /// </summary> /// <param name="A">被解压的流</param> /// <param name="B">要输出的流</param> /// <param name="Length">被解压的数据长度</param> /// <returns>解压的数据长度</returns> public static int DeflateDecodeTo(Stream A, Stream B, int Length = 0) { ZInputStream tDecode = new ZInputStream(A); byte[] tBuffer = new byte[8192]; // 8kb缓冲区 int tLen = 0; int tTotal = 0; while ((tLen = tDecode.read(tBuffer, 0, (Length - tTotal > 8192 ? 8192 : Length - tTotal))) > 0) { tTotal += tLen; B.Write(tBuffer, 0, tLen); } if (Length != 0 && tTotal != Length) throw new IndexOutOfRangeException(); return tTotal; }
public static OSD ZDecompressBytesToOsd(byte[] input) { OSD osd = null; using (MemoryStream msSinkUnCompressed = new MemoryStream()) { using(ZInputStream zOut = new ZInputStream(msSinkUnCompressed)) { zOut.Read(input, 0, input.Length); msSinkUnCompressed.Seek(0L, SeekOrigin.Begin); osd = OSDParser.DeserializeLLSDBinary(msSinkUnCompressed.ToArray()); zOut.Close(); } } return osd; }
public byte[] DecompressPacket(byte[] Payload, int Offset) { MemoryStream ms = new MemoryStream(Payload.GetUpperBound(0) - Offset); ms.Write(Payload, Offset, Payload.GetUpperBound(0) - Offset); ms.Seek(0, System.IO.SeekOrigin.Begin); ZInputStream zs = new ZInputStream(ms); int UncompressedSize; byte[] Uncompressed = new byte[4096]; try { UncompressedSize = zs.read(Uncompressed, 0, 4096); } catch { if(DEBUG) Debug("DECOMPRESSION FAILURE"); Array.Copy(Payload, Offset - 1, Uncompressed, 0, Payload.Length - (Offset - 1)); UncompressedSize = Payload.Length - (Offset - 1); } zs.Close(); zs.Dispose(); ms.Close(); ms.Dispose(); Array.Resize(ref Uncompressed, UncompressedSize); return Uncompressed; }
public static void UnpackSng(Stream input, Stream output, Platform platform) { EndianBitConverter conv; switch (platform.platform) { case GamePlatform.Pc: case GamePlatform.Mac: // Desktop conv = EndianBitConverter.Little; break; case GamePlatform.XBox360: case GamePlatform.PS3: // Console conv = EndianBitConverter.Big; break; default: conv = EndianBitConverter.Little; break; } using (var decrypted = new MemoryStream()) using (var br = new EndianBinaryReader(conv, input)) using (var brDec = new EndianBinaryReader(conv, decrypted)) { byte[] key; switch (platform.platform) { case GamePlatform.Mac: key = RijndaelEncryptor.SngKeyMac; break; default: //PC key = RijndaelEncryptor.SngKeyPC; break; } RijndaelEncryptor.DecryptSngData(br.BaseStream, decrypted, key); //unZip int bSize = 1; uint zLen = brDec.ReadUInt32(); ushort xU = brDec.ReadUInt16(); brDec.BaseStream.Position -= 2; if (xU == 55928) {//LE 55928 //BE 30938 var z = new zlib.ZInputStream(brDec.BaseStream); do { byte[] buf = new byte[bSize]; z.read(buf, 0, bSize); output.Write(buf, 0, bSize); } while (output.Length < (long)zLen); z.Close(); } } }
private ZInputStream reader; // seriously, why isn't this a stream? #endregion Fields #region Constructors public ZLibStream(Stream stream) { reader = new ZInputStream(stream); }