コード例 #1
0
ファイル: Writer.cs プロジェクト: MGRich/sonic-3-mixed
        public void WriteCompressed(byte[] bytes)
        {
            using (MemoryStream outMemoryStream = new MemoryStream())
                using (ZOutputStream compress = new ZOutputStream(outMemoryStream, zlibConst.Z_DEFAULT_COMPRESSION)) {
                    compress.Write(bytes, 0, bytes.Length);
                    compress.finish();

                    byte[] data = outMemoryStream.ToArray();
                    this.Write((uint)data.Length + sizeof(uint));
                    this.WriteUInt32BE((uint)bytes.Length);
                    this.Write(data);
                }
        }
コード例 #2
0
 public static byte[] Compress(byte[] inputBytes)
 {
     byte[] buffer;
     using (MemoryStream stream = new MemoryStream())
     {
         using (ZOutputStream stream2 = new ZOutputStream((Stream)stream, -1))
         {
             stream2.Write(inputBytes, 0, inputBytes.Length);
             stream2.finish();
             buffer = stream.ToArray();
         }
     }
     return(buffer);
 }
コード例 #3
0
        public byte[] Encompress(byte[] data)
        {
            MemoryStream outputStream = new MemoryStream();
            //压缩
            ZOutputStream zStream = new ZOutputStream(outputStream, zlib.zlibConst.Z_DEFAULT_COMPRESSION);

            zStream.Write(data, 0, data.Length);
            zStream.finish();
            byte[] result = outputStream.ToArray();
            zStream.Close();
            outputStream.Close();
            outputStream.Dispose();
            return(result);
        }
コード例 #4
0
ファイル: ArchivePacker.cs プロジェクト: stsuper/TTG_Tools
        private static byte[] ZlibCompressor(byte[] bytes) //Для старых архивов (с версии 3 по 7)
        {
            byte[] retBytes;
            using (MemoryStream outMemoryStream = new MemoryStream())
                using (ZOutputStream outZStream = new ZOutputStream(outMemoryStream, zlibConst.Z_BEST_COMPRESSION))
                    using (Stream inMemoryStream = new MemoryStream(bytes))
                    {
                        CopyStream(inMemoryStream, outZStream);
                        outZStream.finish();
                        retBytes = outMemoryStream.ToArray();
                    }

            return(retBytes);
        }
コード例 #5
0
        private bool ReplaceContentHelperFunc(byte[] content, FileStream datFileStream)
        {
            // Store the old offsets just in case we need to perform a restore.
            // This actually isn't necessary currently, since the raf directory file is saved after packing.
            var oldOffset = FileOffset;
            var oldSize   = FileSize;

            try
            {
                // Navigate to the end of it
                datFileStream.Seek(0, SeekOrigin.End);
                var offset = (UInt32)datFileStream.Length;

                var fInfo = new FileInfo(FileName);

                // .fsb, .fev, and .gfx files aren't compressed
                byte[] finalContent;
                if (fInfo.Extension == ".fsb" || fInfo.Extension == ".fev" || fInfo.Extension == ".gfx")
                {
                    finalContent = content;
                }
                else
                {
                    // Start of compression
                    var mStream = new MemoryStream();
                    var oStream = new ZOutputStream(mStream, zlibConst.Z_DEFAULT_COMPRESSION);
                    //using default compression level
                    oStream.Write(content, 0, content.Length);
                    oStream.finish();
                    finalContent = mStream.ToArray();
                }

                // Write the data to the end of the .dat file
                datFileStream.Write(finalContent, 0, finalContent.Length);

                // Update entry values to represent the new changes
                FileOffset = offset;
                FileSize   = (UInt32)finalContent.Length;

                return(true);
            }
            catch (Exception)
            {
                FileOffset = oldOffset;
                FileSize   = oldSize;

                return(false);
            }
        }
コード例 #6
0
 /// <summary>
 /// 压缩流
 /// </summary>
 /// <param name="SourceStream">需要被压缩的流数据</param>
 /// <returns></returns>
 public static Stream CompressStream(Stream SourceStream)
 {
     try
     {
         MemoryStream  stmOutTemp = new MemoryStream();
         ZOutputStream outZStream = new ZOutputStream(stmOutTemp, zlibConst.Z_DEFAULT_COMPRESSION);
         CopyStream(SourceStream, outZStream);
         outZStream.finish();
         return(stmOutTemp);
     }
     catch
     {
         return(null);
     }
 }
コード例 #7
0
ファイル: Main.cs プロジェクト: Rex109/RayKaster
        public static string DecompressString(byte[] buffer)
        {
            MemoryStream  memOutput = new MemoryStream();
            ZOutputStream zipOut    = new ZOutputStream(memOutput);

            zipOut.Write(buffer, 0, buffer.Length);
            zipOut.finish();

            memOutput.Seek(0, SeekOrigin.Begin);
            byte[] result = memOutput.ToArray();

            var str = System.Text.Encoding.Default.GetString(result);

            return(str);
        }
コード例 #8
0
ファイル: Main.cs プロジェクト: Rex109/RayKaster
        public static byte[] CompressString(string source)
        {
            byte[] buffer = System.Text.Encoding.Default.GetBytes(source);

            MemoryStream  memOutput = new MemoryStream();
            ZOutputStream zipOut    = new ZOutputStream(memOutput, zlibConst.Z_BEST_SPEED);

            zipOut.Write(buffer, 0, buffer.Length);
            zipOut.finish();

            memOutput.Seek(0, SeekOrigin.Begin);
            byte[] result = memOutput.ToArray();

            return(result);
        }
コード例 #9
0
 private static void DecompressData(byte[] inData, out byte[] outData)
 {
     using (MemoryStream outMemoryStream = new MemoryStream())
     {
         using (ZOutputStream outZStream = new ZOutputStream(outMemoryStream))
         {
             using (Stream inMemoryStream = new MemoryStream(inData))
             {
                 CopyStream(inMemoryStream, outZStream);
                 outZStream.finish();
                 outData = outMemoryStream.ToArray();
             }
         }
     }
 }
コード例 #10
0
 public static void DecompressData(byte[] inData, out byte[] outData)
 {
     using (MemoryStream outMemoryStream = new MemoryStream())
         using (ZOutputStream outZStream = new ZOutputStream(outMemoryStream))
             using (Stream inMemoryStream = new MemoryStream(inData))
             {
                 try
                 {
                     CopyStream(inMemoryStream, outZStream);
                     outZStream.finish();
                     outData = outMemoryStream.ToArray();
                 }
                 catch { outData = new byte[0]; }
             }
 }
コード例 #11
0
 public static Stream DecompressStream(Stream SourceStream)
 {
     try
     {
         MemoryStream  stmOutput  = new MemoryStream();
         ZOutputStream outZStream = new ZOutputStream(stmOutput);
         CopyStream(SourceStream, outZStream);
         outZStream.finish();
         return(stmOutput);
     }
     catch
     {
         return(null);
     }
 }
コード例 #12
0
        /// <summary>
        /// Compress an OSD.
        /// </summary>
        /// <returns>The compressed OSD</returns>
        /// <param name="inOsd">In osd.</param>
        /// <param name="useHeader">If set to <c>true</c> use header.</param>
        public static OSD ZCompressOSD(OSD inOsd, bool useHeader)
        {
            OSD osd;

            using (MemoryStream msSinkCompressed = new MemoryStream()) {
                using (ZOutputStream zOut = new ZOutputStream(msSinkCompressed, zlibConst.Z_DEFAULT_COMPRESSION)) {
                    CopyStream(new MemoryStream(OSDParser.SerializeLLSDBinary(inOsd, useHeader)), zOut);
                    zOut.finish();

                    osd = OSD.FromBinary(msSinkCompressed.ToArray());
                }
            }

            return(osd);
        }
コード例 #13
0
        /// <summary>
        /// 字节解压缩(暂时未优化性能)
        /// </summary>
        public static byte[] uncompressByteArr(byte[] bytes, int off, int len)
        {
            MemoryStream  stream = new MemoryStream();
            ZOutputStream zs     = new ZOutputStream(stream);

            zs.Write(bytes, off, len);
            zs.finish();

            byte[] re = stream.ToArray();

            zs.Close();
            stream.Close();

            return(re);
        }
コード例 #14
0
        public void DecompressChunkToStream(MemoryStream aOutput)
        {
            var chunkPosition = BaseStream.Position + 4;
            var chunk         = ReadChunk();

            try {
                ZOutputStream zlibStream = new ZOutputStream(aOutput);
                zlibStream.Write(chunk, 0, chunk.Length);
                zlibStream.finish();
                zlibStream.end();
            }
            catch (ZStreamException e) {
                throw new Exceptions.FileCorrupted(chunkPosition, e.Message);
            }
        }
コード例 #15
0
        /** 字节压缩buffer池 */
        //private static ObjectPoolSafe<BytesCompressData> _compressBufferPool = new ObjectPoolSafe<BytesCompressData>(()=> { return new BytesCompressData(); });

        /// <summary>
        /// 字节压缩(暂时未优化性能)
        /// </summary>
        public static byte[] compressByteArr(byte[] bytes, int off, int len)
        {
            MemoryStream  stream = new MemoryStream();
            ZOutputStream zs     = new ZOutputStream(stream, zlibConst.Z_BEST_COMPRESSION);

            zs.Write(bytes, off, len);
            zs.finish();

            byte[] re = stream.ToArray();

            zs.Close();
            stream.Close();

            return(re);
        }
コード例 #16
0
        public static byte[] ZCompressOSD(OSD data)
        {
            byte[] ret = null;

            using (MemoryStream outMemoryStream = new MemoryStream())
                using (ZOutputStream outZStream = new ZOutputStream(outMemoryStream, zlibConst.Z_BEST_COMPRESSION))
                    using (Stream inMemoryStream = new MemoryStream(OSDParser.SerializeLLSDBinary(data, false)))
                    {
                        CopyStream(inMemoryStream, outZStream);
                        outZStream.finish();
                        ret = outMemoryStream.ToArray();
                    }

            return(ret);
        }
コード例 #17
0
 public static byte[] DecompressData(byte[] inData)
 {
     using (MemoryStream outMemoryStream = new MemoryStream())
     {
         using (ZOutputStream outZStream = new ZOutputStream(outMemoryStream))
         {
             using (Stream inMemoryStream = new MemoryStream(inData))
             {
                 CopyStream(inMemoryStream, outZStream);
                 outZStream.finish();
                 return(outMemoryStream.ToArray());
             }
         }
     }
     return(null);
 }
コード例 #18
0
        public ReplayDB(Reader reader)
        {
            using (MemoryStream outMemoryStream = new MemoryStream())
            {
                using (ZOutputStream decompress = new ZOutputStream(outMemoryStream))
                {
                    decompress.Write(reader.ReadBytes(reader.BaseStream.Length), 0, (int)reader.BaseStream.Length);
                    decompress.finish();
                    reader.Close();
                }

                // Reader creader = new Reader(outMemoryStream);

                //creader.Close();
            }
        }
コード例 #19
0
ファイル: Database.cs プロジェクト: thegamerz/CharacterEditor
        private static void CompressData(byte[] inData, out byte[] outData)
        {
            using (MemoryStream outMemoryStream = new MemoryStream())
            {
                using (ZOutputStream outZStream = new ZOutputStream(outMemoryStream, zlibConst.Z_DEFAULT_COMPRESSION))
                {
                    using (Stream inMemoryStream = new MemoryStream(inData))
                    {
                        CopyStream(inMemoryStream, outZStream);
                        outZStream.finish();

                        outData = outMemoryStream.ToArray();
                    }
                }
            }
        }
コード例 #20
0
        public static OSD ZDecompressOSD(byte[] data)
        {
            OSD ret;

            using (MemoryStream input = new MemoryStream(data))
                using (MemoryStream output = new MemoryStream())
                    using (ZOutputStream zout = new ZOutputStream(output))
                    {
                        CopyStream(input, zout);
                        zout.finish();
                        output.Seek(0, SeekOrigin.Begin);
                        ret = OSDParser.DeserializeLLSDBinary(output);
                    }

            return(ret);
        }
コード例 #21
0
 public static byte[] CompressData(byte[] inData)
 {
     using (MemoryStream outMemoryStream = new MemoryStream())
     {
         using (ZOutputStream outZStream = new ZOutputStream(outMemoryStream, zlibConst.Z_DEFAULT_COMPRESSION))
         {
             using (Stream inMemoryStream = new MemoryStream(inData))
             {
                 CopyStream(inMemoryStream, outZStream);
                 outZStream.finish();
                 return(outMemoryStream.ToArray());
             }
         }
     }
     return(null);
 }
コード例 #22
0
ファイル: DataFile.cs プロジェクト: Matodor/TeeSharp
        public T GetData <T>(int index)
        {
            if (_dataObjects[index] != null)
            {
                return((T)_dataObjects[index]);
            }

            var dataSize         = GetDataSize(index);
            var uncompressedSize = DataSizes[index];

            Debug.Log("datafile", $"loading data={typeof(T).Name} index={index} size={dataSize} uncompressed={uncompressedSize}");
            using (var outMemoryStream = new MemoryStream())
                using (var outZStream = new ZOutputStream(outMemoryStream))
                    using (var inMemoryStream = new MemoryStream(
                               Raw,
                               DataStartIndex + DataOffsets[index],
                               dataSize
                               ))
                    {
                        inMemoryStream.CopyTo(outZStream);
                        outZStream.finish();

                        // TODO
                        if (typeof(T).IsArray)
                        {
                            if (typeof(T) == typeof(string[]))
                            {
                                throw new NotSupportedException("GetData not supported array string");
                            }

                            _dataObjects[index] = outMemoryStream.ToArray().AsSpan().ReadArray <T>();
                        }
                        else
                        {
                            if (typeof(T) == typeof(string))
                            {
                                _dataObjects[index] = Encoding.UTF8.GetString(outMemoryStream.ToArray()).SanitizeCC();
                            }
                            else
                            {
                                _dataObjects[index] = outMemoryStream.ToArray().AsSpan().Read <T>();
                            }
                        }
                    }

            return((T)_dataObjects[index]);
        }
コード例 #23
0
 protected static byte[] Decompress(string path)
 {
     using (var ms = new MemoryStream())
         using (var in_fs = new FileStream(path, FileMode.Open))
             using (var zlib = new ZOutputStream(ms))
             {
                 int len;
                 var buf = new byte[512];
                 while ((len = in_fs.Read(buf, 0, buf.Length)) > 0)
                 {
                     zlib.Write(buf, 0, len);
                 }
                 zlib.Flush();
                 zlib.finish();
                 return(ms.ToArray());
             }
 }
コード例 #24
0
        public static byte[] DecryptData(byte[] bytes)
        {
            var stream  = new MemoryStream();
            var zStream = new ZOutputStream(stream);

            zStream.Write(bytes, 0, bytes.Length);
            zStream.Flush();

            bytes           = new byte[stream.Length];
            stream.Position = 0;
            stream.Read(bytes, 0, bytes.Length);
            stream.Close();
            zStream.finish();
            zStream.Close();

            return(Convert.FromBase64String(Encoding.UTF8.GetString(bytes)));
        }
コード例 #25
0
        /// <summary>
        /// Decompress bytes to osd.
        /// </summary>
        /// <returns>The decompressed osd.</returns>
        /// <param name="input">Input.</param>
        public static OSD ZDecompressBytesToOsd(byte [] input)
        {
            OSD osd;

            using (MemoryStream msSinkUnCompressed = new MemoryStream()) {
                using (ZOutputStream zOut = new ZOutputStream(msSinkUnCompressed)) {
                    using (Stream inMs = new MemoryStream(input)) {
                        CopyStream(inMs, zOut);
                        zOut.finish();

                        osd = OSDParser.DeserializeLLSDBinary(msSinkUnCompressed.ToArray());
                    }
                }
            }

            return(osd);
        }
コード例 #26
0
        public static byte[] Deflate(byte[] buffer)
        {
            using (var iStream = new MemoryStream(buffer))
            {
                using (var oStream = new MemoryStream())
                {
                    using (var zStream = new ZOutputStream(oStream, -1))
                    {
                        CopyStream(iStream, zStream);

                        zStream.finish();

                        return(oStream.ToArray());
                    }
                }
            }
        }
コード例 #27
0
 private static byte[] DecompressBlob(byte[] inData)
 {
     using (MemoryStream outStream = new MemoryStream())
         using (MemoryStream inStream = new MemoryStream(inData))
             using (ZOutputStream outZStream = new ZOutputStream(outStream))
             {
                 inStream.Seek(8, 0);
                 byte[] buffer = new byte[16384];
                 int    len;
                 while ((len = inStream.Read(buffer, 0, buffer.Length)) > 0)
                 {
                     outZStream.Write(buffer, 0, len);
                 }
                 outZStream.Flush();
                 outZStream.finish();
                 return(outStream.ToArray());
             }
 }
コード例 #28
0
ファイル: CompressedStream.cs プロジェクト: Jackjet/ECOSingle
        private MemoryStream CompressCache()
        {
            if (this.cache.Length < 50L)
            {
                return(null);
            }
            byte[]        buffer        = this.cache.GetBuffer();
            MemoryStream  memoryStream  = new MemoryStream();
            ZOutputStream zOutputStream = new ZOutputStream(memoryStream, -1);

            zOutputStream.Write(buffer, 0, (int)this.cache.Length);
            zOutputStream.finish();
            if (memoryStream.Length >= this.cache.Length)
            {
                return(null);
            }
            return(memoryStream);
        }
コード例 #29
0
    /// <summary>
    /// 解压缩
    /// </summary>
    public static byte[] Uncompress(byte[] sourceByte)
    {
        MemoryStream  inStream   = new MemoryStream(sourceByte);
        MemoryStream  outStream  = new MemoryStream();
        ZOutputStream zilbStream = new ZOutputStream(outStream);

        zilbStream.Write(sourceByte, 0, sourceByte.Length);
        zilbStream.Flush();
        zilbStream.finish();

        byte[] bytes = new byte[outStream.Length];
        outStream.Position = 0;
        outStream.Read(bytes, 0, bytes.Length);

        inStream.Close();
        outStream.Close();

        return(bytes);
    }
コード例 #30
0
ファイル: PacketHelper.cs プロジェクト: dghkd/FlowerMaster
        /// <summary>
        /// 对日服数据包的内容进行解压以及转码
        /// <para>源数据→zlib解压→base64转码→json数据</para>
        /// </summary>
        /// <param name="source"></param>
        /// <returns></returns>
        private static string DecryptData(byte[] source)
        {
            MemoryStream  resultStream = new MemoryStream();
            ZOutputStream outStream    = new ZOutputStream(resultStream);

            outStream.Write(source, 0, source.Length);
            outStream.Flush();
            outStream.finish();
            byte[] buffer = new byte[resultStream.Length];
            resultStream.Position = 0;
            resultStream.Read(buffer, 0, buffer.Length);
            resultStream.Close();
            outStream.Close();

            return(Encoding.UTF8.GetString(buffer));

            //2019/06/17更新新版後資料無Base64編碼
            //return Encoding.UTF8.GetString(Convert.FromBase64String(Encoding.UTF8.GetString(buffer)));
        }
コード例 #31
0
ファイル: Helpers.cs プロジェクト: VirtualReality/LibOMV
        public static OSD ZDecompressOSD(byte[] data)
        {
            OSD ret;

            using (MemoryStream input = new MemoryStream(data))
            using (MemoryStream output = new MemoryStream())
            using (ZOutputStream zout = new ZOutputStream(output))
            {
                CopyStream(input, zout);
                zout.finish();
                output.Seek(0, SeekOrigin.Begin);
                ret = OSDParser.DeserializeLLSDBinary(output);
            }

            return ret;
        }
コード例 #32
0
ファイル: Helpers.cs プロジェクト: VirtualReality/LibOMV
        public static byte[] ZCompressOSD(OSD data)
        {
            byte[] ret = null;

            using (MemoryStream outMemoryStream = new MemoryStream())
            using (ZOutputStream outZStream = new ZOutputStream(outMemoryStream, zlibConst.Z_BEST_COMPRESSION))
            using (Stream inMemoryStream = new MemoryStream(OSDParser.SerializeLLSDBinary(data, false)))
            {
                CopyStream(inMemoryStream, outZStream);
                outZStream.finish();
                ret = outMemoryStream.ToArray();
            }

            return ret;
        }
コード例 #33
0
        /// <summary>
        /// Decompress bytes to osd.
        /// </summary>
        /// <returns>The decompressed osd.</returns>
        /// <param name="input">Input.</param>
        public static OSD ZDecompressBytesToOsd(byte[] input)
        {
            OSD osd;

            using (MemoryStream msSinkUnCompressed = new MemoryStream())
            {
                using (ZOutputStream zOut = new ZOutputStream(msSinkUnCompressed))
                {
                    using (Stream inMs = new MemoryStream(input))
                    {
                        CopyStream(inMs, zOut);
                        zOut.finish();

                        osd = OSDParser.DeserializeLLSDBinary(msSinkUnCompressed.ToArray());
                    }
                }
            }

            return osd;
        }
コード例 #34
0
        /// <summary>
        /// Compress an OSD.
        /// </summary>
        /// <returns>The compressed OSD</returns>
        /// <param name="inOsd">In osd.</param>
        /// <param name="useHeader">If set to <c>true</c> use header.</param>
        public static OSD ZCompressOSD(OSD inOsd, bool useHeader)
        {
            OSD osd;

            using (MemoryStream msSinkCompressed = new MemoryStream())
            {
                using (ZOutputStream zOut = new ZOutputStream(msSinkCompressed, zlibConst.Z_DEFAULT_COMPRESSION))
                {
                    CopyStream(new MemoryStream(OSDParser.SerializeLLSDBinary(inOsd, useHeader)), zOut);
                    zOut.finish();

                    osd = OSD.FromBinary(msSinkCompressed.ToArray());
                }
            }

            return osd;
        }
コード例 #35
0
        /// <summary>
        /// decompresses a gzipped OSD object
        /// </summary>
        /// <param name="meshBytes"></param>
        /// <returns></returns>
        static OSD DecompressOsd (byte [] meshBytes)
        {
            OSD decodedOsd = null;

            using (MemoryStream outMs = new MemoryStream ()) {
                using (ZOutputStream zOut = new ZOutputStream (outMs)) {
                    using (Stream inMs = new MemoryStream (meshBytes)) {
                        byte [] readBuffer = new byte [meshBytes.Length];
                        int readLen;

                        while ((readLen = inMs.Read (readBuffer, 0, readBuffer.Length)) > 0) {
                            zOut.Write (readBuffer, 0, readLen);
                        }
                        zOut.Flush ();
                        zOut.finish ();

                        byte [] decompressedBuf = outMs.GetBuffer (); //  ToArray();

                        decodedOsd = OSDParser.DeserializeLLSDBinary (decompressedBuf);
                    }
                }
            }

            return decodedOsd;
        }