Beispiel #1
0
        /// <summary>
        /// Writes a compressed string.
        /// </summary>
        public void WriteCompressedString(string value)
        {
            if (value != null)
            {
                int length = value.Length;

                if (length > 100)
                {
                    this.WriteByte(1);

                    byte[] compressed = ZlibStream.CompressString(value);

                    this.WriteInt(compressed.Length + 4);
                    this.WriteIntEndian(length);
                    this.Write(compressed);
                }
                else
                {
                    this.WriteByte(0);
                    this.WriteString(value);
                }
            }
            else
            {
                this.WriteByte(0);
                this.WriteInt(0);
            }
        }
Beispiel #2
0
        public static void AddCompressed(this List <byte> _Packet, string _Value, bool addbool = true)
        {
            if (addbool)
            {
                _Packet.AddBool(Constants.PacketCompression);
            }

            if (Constants.PacketCompression)
            {
                if (_Value == null)
                {
                    _Packet.AddInt(-1);
                }
                else
                {
                    byte[] Compressed = ZlibStream.CompressString(_Value);

                    _Packet.AddInt(Compressed.Length + 4);
                    _Packet.AddIntEndian(_Value.Length);
                    _Packet.AddRange(Compressed);
                }
            }
            else
            {
                _Packet.AddString(_Value);
            }
        }
        /// <summary>
        /// Writes the <see cref="AvatarProfileResponseMessage"/> to the specified <see cref="MessageWriter"/>.
        /// </summary>
        /// <param name="writer">
        /// <see cref="MessageWriter"/> that will be used to write the <see cref="AvatarProfileResponseMessage"/>.
        /// </param>
        public override void WriteMessage(MessageWriter writer)
        {
            if (AvatarData == null)
            {
                throw new InvalidOperationException("AvatarData cannot be null.");
            }

            AvatarData.WriteMessageComponent(writer);

            var mem = new MemoryStream();

            using (var bw = new BinaryWriter(mem))
            {
                var villageJson       = VillageJson;
                var compressedVillage = ZlibStream.CompressString(villageJson);

                bw.Write(villageJson.Length);
                bw.Write(compressedVillage);
                writer.Write(mem.ToArray(), true);
            }

            writer.Write(TroopsDonated);
            writer.Write(TroopsReceived);
            writer.Write((int)WarCoolDown.TotalSeconds);

            writer.Write(Unknown2);
            writer.Write(Unknown3);
        }
Beispiel #4
0
        private static string JsonToBpString(string json)
        {
            var zlibBpString   = ZlibStream.CompressString(json);
            var base64BpString = Convert.ToBase64String(zlibBpString);

            return(base64BpString);
        }
Beispiel #5
0
        public static void AddCompressableString(this List <byte> _Writer, string String)
        {
            if (String != null)
            {
                int length = String.Length;

                if (length > 100)
                {
                    _Writer.Add(1);

                    byte[] Compressed = ZlibStream.CompressString(String);

                    _Writer.AddInt(Compressed.Length + 4);
                    _Writer.AddIntEndian(length);
                    _Writer.AddRange(Compressed);
                }
                else
                {
                    _Writer.Add(0);
                    _Writer.AddString(String);
                }
            }
            else
            {
                _Writer.Add(0);
                _Writer.AddInt(0);
            }
        }
Beispiel #6
0
        public override void Encode()
        {
            List <byte> data = new List <byte>();
            string      text = File.ReadAllText("replay-json.txt");

            data.AddRange(ZlibStream.CompressString(text));
            Encrypt(data.ToArray());
        }
Beispiel #7
0
        /// <summary>
        /// Adds the compressed data.
        /// </summary>
        /// <param name="_Packet">The packet.</param>
        /// <param name="_Value">The value.</param>
        public static void AddCompressed(this List <byte> _Packet, string _Value)
        {
            byte[] Compressed = ZlibStream.CompressString(_Value);

            _Packet.AddInt(Compressed.Length + 4);
            _Packet.AddInt(_Value.Length);
            _Packet.AddRange(Compressed);
        }
Beispiel #8
0
        internal static void AddCompressedString(this ByteWriter Writer, string Value)
        {
            byte[] Data = ZlibStream.CompressString(Value);

            Writer.AddInt(Data.Length + 4);
            Writer.AddIntEndian(Value.Length);
            Writer.AddRange(Data);
        }
Beispiel #9
0
        /// <summary>
        /// Encodes the <see cref="Message" />, using the <see cref="Writer" /> instance.
        /// </summary>
        internal override void Encode()
        {
            byte[] Compressed = ZlibStream.CompressString(this.Replay);

            this.Data.AddInt(Compressed.Length + 4);
            this.Data.AddIntEndian(this.Replay.Length);
            this.Data.AddRange(Compressed);
        }
Beispiel #10
0
        public static byte[] SerializeAndCompressResults(Logging.ProcessedPost post)
        {
            if (post.AnalysisResults == null)
            {
                return(null);
            }

            string jsonAnalysisResults = JsonConvert.SerializeObject(post.AnalysisResults);

            return(ZlibStream.CompressString(jsonAnalysisResults));
        }
Beispiel #11
0
        private void Run()
        {
            Console.WriteLine("Compressing a string...");

            int lengthOriginal = GoPlacidly.Length;

            // do the compression:
            byte[] b = ZlibStream.CompressString(GoPlacidly);

            int lengthCompressed = b.Length;

            Console.WriteLine();
            Console.WriteLine("  Original Length: {0}", lengthOriginal);
            Console.WriteLine("Compressed Length: {0}", lengthCompressed);
            Console.WriteLine("    Compression %: {0:n1}%", lengthCompressed / (0.01 * lengthOriginal));
            Console.WriteLine("Compressed Data  : {0}", ByteArrayToHexString(b));
            Console.WriteLine();

            // now let's do some timed trials
            Console.WriteLine("Doing timing runs....");
            CompressionTrialResult result;

            result = DoTrial("Zlib",
                             ZlibStream.CompressString,
                             ZlibStream.UncompressString,
                             GoPlacidly,
                             10000);
            result.Show();
            result = DoTrial("GZip",
                             GZipStream.CompressString,
                             GZipStream.UncompressString,
                             GoPlacidly,
                             10000);
            result.Show();

            result = DoTrial("Deflate",
                             DeflateStream.CompressString,
                             DeflateStream.UncompressString,
                             GoPlacidly,
                             10000);
            result.Show();

            // All these classes use the same underlying algorithm - DEFLATE -
            // which means they all produce compressed forms that are roughly the
            // same size. The difference between them is only in the metadata
            // surrounding the raw compressed streams, and the level of integrity
            // checking they provide. For example, during compression, the
            // GzipStream internally calculates an Alder checksum on the data;
            // during decompression, it verifies that checksum, as an integrity
            // check. The other classes don't do this. Therefore the GZipStream
            // will always take slightly longer in compression and decompression
            // than the others, and will produce compressed streams that are
            // slightly larger.  The results will show that.
        }
        /// <summary>
        /// Writes the <see cref="VillageMessageComponent"/> to the specified <see cref="MessageWriter"/>.
        /// </summary>
        /// <param name="writer">
        /// <see cref="MessageWriter"/> that will be used to write the <see cref="VillageMessageComponent"/>.
        /// </param>
        /// <exception cref="ArgumentNullException"><paramref name="writer"/> is null.</exception>
        public override void WriteMessageComponent(MessageWriter writer)
        {
            ThrowIfWriterNull(writer);

            writer.Write(HomeId);
            writer.Write((int)ShieldDuration.TotalSeconds);
            writer.Write((int)GuardDuration.TotalSeconds); // 1800 = 8.x.x

            writer.Write(Unknown1);                        // 69119 = 8.x.x seems to change, might be a TimeSpan.

            if (VillageJson != null)
            {
                writer.Write(true);

                // Uses BinaryWriter for little-endian writing.
                var mem = new MemoryStream();
                using (var bw = new BinaryWriter(mem))
                {
                    var homeJson           = VillageJson;
                    var compressedHomeJson = ZlibStream.CompressString(homeJson);

                    bw.Write(homeJson.Length);
                    bw.Write(compressedHomeJson);
                    writer.Write(mem.ToArray(), true);
                }
            }
            else
            {
                writer.Write(false);
            }

            if (EventJson != null)
            {
                writer.Write(true);

                // Uses BinaryWriter for little-endian writing.
                var mem = new MemoryStream();
                using (var bw = new BinaryWriter(mem))
                {
                    var eventJson           = EventJson;
                    var compressedEventJson = ZlibStream.CompressString(eventJson);

                    bw.Write(eventJson.Length);
                    bw.Write(compressedEventJson);
                    writer.Write(mem.ToArray(), true);
                }
            }
            else
            {
                writer.Write(false);
            }
        }
Beispiel #13
0
        /// <summary>
        /// Adds the compressed data.
        /// </summary>
        /// <param name="_Packet">The packet.</param>
        /// <param name="_Value">The value.</param>
        public static void AddCompressed(this List <byte> _Packet, string _Value, bool addbool = true)
        {
            if (addbool)
            {
                _Packet.AddBool(true);
            }

            byte[] Compressed = ZlibStream.CompressString(_Value);

            _Packet.AddInt(Compressed.Length + 4);
            _Packet.AddRange(BitConverter.GetBytes(_Value.Length));
            _Packet.AddRange(Compressed);
        }
Beispiel #14
0
        public void Handle(RequestData data)
        {
            HttpListenerResponse serverResponse = data.Context.Response;

            Log.Info($"Authentication requested from client at {data.Context.Request.RemoteEndPoint}");
            serverResponse.StatusCode  = (int)HttpStatusCode.OK;
            serverResponse.ContentType = "text/plain";
            serverResponse.AddHeader("Content-Encoding", "deflate");
            EftClient client = data.Client;

            byte[] messageBytes = ZlibStream.CompressString(AuthenticationService.Authenticate(ref client, data.Body));
            serverResponse.OutputStream.Write(messageBytes, 0, messageBytes.Length);
            serverResponse.SetCookie(new Cookie("PHPSESSID", client.UniqueSession));;
            serverResponse.Close();
        }
Beispiel #15
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="writer"></param>
        public void WriteToPacketWriter(PacketWriter writer)
        {
            var json = ToJson();
            var decompressedLength = json.Length;
            var compressedJson     = ZlibStream.CompressString(json);

            using (var binaryWriter = new BinaryWriter(new MemoryStream()))
            {
                binaryWriter.Write(decompressedLength);
                binaryWriter.Write(compressedJson);

                var homeData = ((MemoryStream)binaryWriter.BaseStream).ToArray();
                writer.Write(homeData, 0, homeData.Length);
            }
        }
Beispiel #16
0
        public static void EncodeJson(string json)
        {
            if (string.IsNullOrWhiteSpace(json))
            {
                return;
            }
            //compress string with zlib inflation, convert inflated string to base-64 string
            //append it to the constant hash
            //copy to clipboard
            Clipboard.SetText($"{Hash}{Convert.ToBase64String(ZlibStream.CompressString(json))}");

            //inform user about me fecking his clipboard up :)
            MessageBox.Show(@"Encoded save copied to your clipboard.", @"Encoded and copied", MessageBoxButtons.OK, MessageBoxIcon.Asterisk,
                            MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification, false);
        }
Beispiel #17
0
        public void Handle(RequestData data)
        {
            HttpListenerResponse serverResponse = data.Context.Response;

            Log.Info($"Locale requested from client at {data.Context.Request.RemoteEndPoint}");
            serverResponse.StatusCode  = (int)HttpStatusCode.OK;
            serverResponse.ContentType = "text/plain";
            serverResponse.AddHeader("Content-Encoding", "deflate");
            if (data.Client != null)
            {
                serverResponse.SetCookie(new Cookie("PHPSESSID", data.Client.UniqueSession));
            }
            ;
            byte[] messageBytes = ZlibStream.CompressString(Serializer.Read("./Templates/Localization/Languages.json"));
            serverResponse.OutputStream.Write(messageBytes, 0, messageBytes.Length);
            serverResponse.Close();
        }
Beispiel #18
0
    public void putDataBlob(string cmd, TestData data)
    {
        if (connEnable)
        {
            try{
                string uriStr = "http://" + serverUrl + cmd;
                Debug.Log("start Upload url=" + uriStr);
                WebClient client = new WebClient();
                client.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
                //byte[] byteDocs = Encoding.UTF8.GetBytes(JsonUtility.ToJson(data));
                byte[] byteDocs = ZlibStream.CompressString(JsonUtility.ToJson(data));
                client.UploadDataCompleted += new UploadDataCompletedEventHandler(UploadBlobResult);
                client.UploadDataAsync(new System.Uri(uriStr), "POST", byteDocs);

                Debug.Log("Start Uploading result");
            } catch (System.Exception e) {
                Debug.Log("Connection error: " + e);
            }
        }
    }
Beispiel #19
0
        public static void AddCompressedString(this List <byte> list, string data)
        {
            if (data == null)
            {
                list.AddInt32(-1);
            }
            else
            {
                MemoryStream mem = new MemoryStream();
                using (BinaryWriter bw = new BinaryWriter(mem))
                {
                    byte[] compressedString = ZlibStream.CompressString(data);

                    bw.Write(data.Length);
                    bw.Write(compressedString);
                }

                list.AddInt32(mem.ToArray().Length);
                list.AddRange(mem.ToArray());
            }
        }
Beispiel #20
0
        /// <summary>
        /// Writes the <see cref="LoginFailedMessage"/> to the specified <see cref="MessageWriter"/>.
        /// </summary>
        /// <param name="writer">
        /// <see cref="MessageWriter"/> that will be used to write the <see cref="LoginFailedMessage"/>.
        /// </param>
        /// <exception cref="ArgumentNullException"><paramref name="writer"/> is null.</exception>
        public override void WriteMessage(MessageWriter writer)
        {
            ThrowIfWriterNull(writer);

            writer.Write((int)Reason);

            writer.Write(FingerprintJson);

            writer.Write(Hostname);
            writer.Write(ContentUrl);
            writer.Write(MarketUrl);
            writer.Write(Message);
            writer.Write((int)MaintenanceDuration.TotalSeconds);
            writer.Write(Unknown4);

            if (FingerprintJsonCompressed != null)
            {
                // Uses BinaryWriter for little-endian writing.
                var mem = new MemoryStream();
                using (var bw = new BinaryWriter(mem))
                {
                    var fingerprintJson           = FingerprintJsonCompressed;
                    var compressedFingerprintJson = ZlibStream.CompressString(fingerprintJson);

                    bw.Write(fingerprintJson.Length);
                    bw.Write(compressedFingerprintJson);
                    writer.Write(mem.ToArray(), true);
                }
            }
            else
            {
                writer.Write(-1);
            }

            writer.Write(Unknown6);
            writer.Write(Unknown7);
            writer.Write(Unknown8);
            writer.Write(Unknown9);
        }
 public static byte[] CompressZlib(this string source)
 {
     return(ZlibStream.CompressString(source));
 }
Beispiel #22
0
 public void SetHomeJSON(string json)
 {
     m_vSerializedVillage = ZlibStream.CompressString(json);
 }
        // These two data types are supported in DotNetZip, but only if .NET Framework is targeted.
        //private SelfExtractorFlavor _selfExtractorFlavor;
        //private SelfExtractorSaveOptions _selfExtractorSaveOptions;

        public void CallAll()
        {
            // These two apis are supported in DotNetZip, but only if .NET Framework is targeted.
            //_zipFile.SaveSelfExtractor(_string, _selfExtractorFlavor);
            //_zipFile.SaveSelfExtractor(_string, _selfExtractorSaveOptions);

            //Project: Ionic.Zip
            _bZip2InputStream.Close();
            _bZip2InputStream.Flush();
            _int  = _bZip2InputStream.Read(_bytes, _int, _int);
            _int  = _bZip2InputStream.ReadByte();
            _long = _bZip2InputStream.Seek(_long, _seekOrigin);
            _bZip2InputStream.SetLength(_long);
            _bZip2InputStream.Write(_bytes, _int, _int);
            _bZip2OutputStream.Close();
            _bZip2OutputStream.Flush();
            _int  = _bZip2OutputStream.Read(_bytes, _int, _int);
            _long = _bZip2OutputStream.Seek(_long, _seekOrigin);
            _bZip2OutputStream.SetLength(_long);
            _bZip2OutputStream.Write(_bytes, _int, _int);
            _parallelBZip2OutputStream.Close();
            _parallelBZip2OutputStream.Flush();
            _int  = _parallelBZip2OutputStream.Read(_bytes, _int, _int);
            _long = _parallelBZip2OutputStream.Seek(_long, _seekOrigin);
            _parallelBZip2OutputStream.SetLength(_long);
            _parallelBZip2OutputStream.Write(_bytes, _int, _int);
            _crc32.Combine(_int, _int);
            _int = _crc32.ComputeCrc32(_int, _byte);
            _int = _crc32.GetCrc32(_stream);
            _int = _crc32.GetCrc32AndCopy(_stream, _stream);
            _crc32.Reset();
            _crc32.SlurpBlock(_bytes, _int, _int);
            _crc32.UpdateCRC(_byte);
            _crc32.UpdateCRC(_byte, _int);
            _crcCalculatorStream.Close();
            _crcCalculatorStream.Flush();
            _int  = _crcCalculatorStream.Read(_bytes, _int, _int);
            _long = _crcCalculatorStream.Seek(_long, _seekOrigin);
            _crcCalculatorStream.SetLength(_long);
            _crcCalculatorStream.Write(_bytes, _int, _int);
            _zipEntriesCollection = _fileSelector.SelectEntries(_zipFile);
            _zipEntriesCollection = _fileSelector.SelectEntries(_zipFile, _string);
            _stringsCollection    = _fileSelector.SelectFiles(_string);
            _stringsReadOnly      = _fileSelector.SelectFiles(_string, _bool);
            _string = _fileSelector.ToString();
            _bool   = _comHelper.CheckZip(_string);
            _bool   = _comHelper.CheckZipPassword(_string, _string);
            _comHelper.FixZipDirectory(_string);
            _string = _comHelper.GetZipLibraryVersion();
            _bool   = _comHelper.IsZipFile(_string);
            _bool   = _comHelper.IsZipFileWithExtract(_string);
            _countingStream.Adjust(_long);
            _countingStream.Flush();
            _int  = _countingStream.Read(_bytes, _int, _int);
            _long = _countingStream.Seek(_long, _seekOrigin);
            _countingStream.SetLength(_long);
            _countingStream.Write(_bytes, _int, _int);
            _zipEntry.Extract();
            _zipEntry.Extract(_extractExistingFileAction);
            _zipEntry.Extract(_string);
            _zipEntry.Extract(_string, _extractExistingFileAction);
            _zipEntry.Extract(_stream);
            _zipEntry.ExtractWithPassword(_extractExistingFileAction, _string);
            _zipEntry.ExtractWithPassword(_string);
            _zipEntry.ExtractWithPassword(_string, _extractExistingFileAction, _string);
            _zipEntry.ExtractWithPassword(_string, _string);
            _zipEntry.ExtractWithPassword(_stream, _string);
            _crcCalculatorStream = _zipEntry.OpenReader();
            _crcCalculatorStream = _zipEntry.OpenReader(_string);
            _zipEntry.SetEntryTimes(_datetime, _datetime, _datetime);
            _string   = _zipEntry.ToString();
            _zipEntry = _zipFile.AddDirectory(_string);
            _zipEntry = _zipFile.AddDirectory(_string, _string);
            _zipEntry = _zipFile.AddDirectoryByName(_string);
            _zipEntry = _zipFile.AddEntry(_string, _bytes);
            _zipEntry = _zipFile.AddEntry(_string, _openDelegate, _closeDelegate);
            _zipEntry = _zipFile.AddEntry(_string, _writeDelegate);
            _zipEntry = _zipFile.AddEntry(_string, _string);
            _zipEntry = _zipFile.AddEntry(_string, _string, _encoding);
            _zipEntry = _zipFile.AddEntry(_string, _stream);
            _zipEntry = _zipFile.AddFile(_string);
            _zipEntry = _zipFile.AddFile(_string, _string);
            _zipFile.AddFiles(_strings);
            _zipFile.AddFiles(_strings, _bool, _string);
            _zipFile.AddFiles(_strings, _string);
            _zipEntry = _zipFile.AddItem(_string);
            _zipEntry = _zipFile.AddItem(_string, _string);
            _zipFile.AddSelectedFiles(_string);
            _zipFile.AddSelectedFiles(_string, _bool);
            _zipFile.AddSelectedFiles(_string, _string);
            _zipFile.AddSelectedFiles(_string, _string, _bool);
            _zipFile.AddSelectedFiles(_string, _string, _string);
            _zipFile.AddSelectedFiles(_string, _string, _string, _bool);
            _bool = _zipFile.ContainsEntry(_string);
            _zipFile.Dispose();
            _zipFile.ExtractAll(_string);
            _zipFile.ExtractAll(_string, _extractExistingFileAction);
            _zipFile.ExtractSelectedEntries(_string);
            _zipFile.ExtractSelectedEntries(_string, _extractExistingFileAction);
            _zipFile.ExtractSelectedEntries(_string, _string);
            _zipFile.ExtractSelectedEntries(_string, _string, _string);
            _zipFile.ExtractSelectedEntries(_string, _string, _string, _extractExistingFileAction);
            _enumerator = _zipFile.GetNewEnum();
            _zipFile.Initialize(_string);
            _zipFile.RemoveEntries(_zipEntriesCollection);
            _zipFile.RemoveEntries(_stringsCollection);
            _zipFile.RemoveEntry(_zipEntry);
            _zipFile.RemoveEntry(_string);
            _int = _zipFile.RemoveSelectedEntries(_string);
            _int = _zipFile.RemoveSelectedEntries(_string, _string);
            _zipFile.Save();
            _zipFile.Save(_string);
            _zipFile.Save(_stream);
            _zipEntriesCollection = _zipFile.SelectEntries(_string);
            _zipEntriesCollection = _zipFile.SelectEntries(_string, _string);
            _string   = _zipFile.ToString();
            _zipEntry = _zipFile.UpdateDirectory(_string);
            _zipEntry = _zipFile.UpdateDirectory(_string, _string);
            _zipEntry = _zipFile.UpdateEntry(_string, _bytes);
            _zipEntry = _zipFile.UpdateEntry(_string, _openDelegate, _closeDelegate);
            _zipEntry = _zipFile.UpdateEntry(_string, _writeDelegate);
            _zipEntry = _zipFile.UpdateEntry(_string, _string);
            _zipEntry = _zipFile.UpdateEntry(_string, _string, _encoding);
            _zipEntry = _zipFile.UpdateEntry(_string, _stream);
            _zipEntry = _zipFile.UpdateFile(_string);
            _zipFile.UpdateFile(_string, _string);
            _zipFile.UpdateFiles(_strings);
            _zipFile.UpdateFiles(_strings, _string);
            _zipFile.UpdateItem(_string);
            _zipFile.UpdateItem(_string, _string);
            _zipFile.UpdateSelectedFiles(_string, _string, _string, _bool);
            _zipInputStream.Flush();
            _zipEntry = _zipInputStream.GetNextEntry();
            _int      = _zipInputStream.Read(_bytes, _int, _int);
            _long     = _zipInputStream.Seek(_long, _seekOrigin);
            _zipInputStream.SetLength(_long);
            _string = _zipInputStream.ToString();
            _zipInputStream.Write(_bytes, _int, _int);
            _bool = _zipOutputStream.ContainsEntry(_string);
            _zipOutputStream.Flush();
            _zipEntry = _zipOutputStream.PutNextEntry(_string);
            _int      = _zipOutputStream.Read(_bytes, _int, _int);
            _long     = _zipOutputStream.Seek(_long, _seekOrigin);
            _zipOutputStream.SetLength(_long);
            _string = _zipOutputStream.ToString();
            _zipOutputStream.Write(_bytes, _int, _int);
            _deflateStream.Flush();
            _int  = _deflateStream.Read(_bytes, _int, _int);
            _long = _deflateStream.Seek(_long, _seekOrigin);
            _deflateStream.SetLength(_long);
            _deflateStream.Write(_bytes, _int, _int);
            _gZipStream.Flush();
            _int  = _gZipStream.Read(_bytes, _int, _int);
            _long = _gZipStream.Seek(_long, _seekOrigin);
            _gZipStream.SetLength(_long);
            _gZipStream.Write(_bytes, _int, _int);
            _parallelDeflateOutputStream.Close();
            _parallelDeflateOutputStream.Flush();
            _int = _parallelDeflateOutputStream.Read(_bytes, _int, _int);
            _parallelDeflateOutputStream.Reset(_stream);
            _long = _parallelDeflateOutputStream.Seek(_long, _seekOrigin);
            _parallelDeflateOutputStream.SetLength(_long);
            _parallelDeflateOutputStream.Write(_bytes, _int, _int);

            // Static
            _bool = ZipFile.CheckZip(_string);
            _bool = ZipFile.CheckZip(_string, _bool, _textWriter);
            _bool = ZipFile.CheckZipPassword(_string, _string);
            ZipFile.FixZipDirectory(_string);
            _bool    = ZipFile.IsZipFile(_string);
            _bool    = ZipFile.IsZipFile(_string, _bool);
            _bool    = ZipFile.IsZipFile(_stream, _bool);
            _zipFile = ZipFile.Read(_string);
            _zipFile = ZipFile.Read(_string, _readOptions);
            _zipFile = ZipFile.Read(_stream);
            _zipFile = ZipFile.Read(_stream, _readOptions);
            _uint    = Adler.Adler32(_uint, _bytes, _int, _int);
            _bytes   = DeflateStream.CompressBuffer(_bytes);
            _bytes   = DeflateStream.CompressString(_string);
            _bytes   = DeflateStream.UncompressBuffer(_bytes);
            _string  = DeflateStream.UncompressString(_bytes);
            _bytes   = GZipStream.CompressBuffer(_bytes);
            _bytes   = GZipStream.CompressString(_string);
            _bytes   = GZipStream.UncompressBuffer(_bytes);
            _string  = GZipStream.UncompressString(_bytes);
            _bytes   = ZlibStream.CompressBuffer(_bytes);
            _bytes   = ZlibStream.CompressString(_string);
            _bytes   = ZlibStream.UncompressBuffer(_bytes);
            _string  = ZlibStream.UncompressString(_bytes);
        }
Beispiel #24
0
        /// <summary>
        /// 圧縮
        /// </summary>
        public byte[] Deflate()
        {
            //データ部圧縮
            //compress datas
            List <int>    originalContentDataSizeTable   = new List <int>();
            List <byte[]> compressedContentDataTable     = new List <byte[]>(_contentFileInfoTable.Count);
            int           compressedContentDataTableSize = 0;

            for (int contentIndex = 0; contentIndex < _contentFileInfoTable.Count; contentIndex++)
            {
                var fileInfo = _contentFileInfoTable[contentIndex];
                var data     = System.IO.File.ReadAllBytes(fileInfo.FullName);
                originalContentDataSizeTable.Add(data.Length);
                var compressed = ZlibStream.CompressBuffer(data);
                compressedContentDataTableSize += compressed.Length;
                compressedContentDataTable.Add(compressed);
            }

            //ファイル名部圧縮
            //compress name table
            byte[] compressedContentNameTable     = null;
            int    compressedContentNameTableSize = 0;

            {
                //全ファイル名結合
                System.Text.StringBuilder builder = new System.Text.StringBuilder();
                foreach (var s in _contentNameTable)
                {
                    builder.Append(s);
                    compressedContentNameTableSize += System.Text.Encoding.UTF8.GetByteCount(s);
                }

                compressedContentNameTable = ZlibStream.CompressString(builder.ToString());
            }

            //コンテンツ情報部圧縮
            //compress contents
            byte[] compressedContentTable = null;
            {
                byte[] headerTable = new byte[SZipContent.Size * _contentFileInfoTable.Count];
                using (MemoryStream stream = new MemoryStream(headerTable))
                {
                    using (BinaryWriter writer = new BinaryWriter(stream))
                    {
                        for (int contentIndex = 0; contentIndex < _contentFileInfoTable.Count; contentIndex++)
                        {
                            var           content = new SZipContent();
                            System.UInt32 crc     = SZipUtility.FNVHash(compressedContentDataTable[contentIndex]);
                            content.Set(_contentNameTable[contentIndex].Length,
                                        originalContentDataSizeTable[contentIndex],
                                        compressedContentDataTable[contentIndex].Length,
                                        crc);
                            content.Write(writer);
                        }
                    }
                }
                compressedContentTable = ZlibStream.CompressBuffer(headerTable);
            }

            //ヘッダ生成
            //create szip header
            var header = new SZipHeader();

            header.Set((System.Int16)_contentFileInfoTable.Count,
                       SZipUtility.FNVHash(compressedContentNameTable),
                       SZipUtility.FNVHash(compressedContentTable),
                       compressedContentTable.Length,
                       compressedContentNameTableSize,
                       compressedContentNameTable.Length);

            //書き込み
            //write to byte[]
            {
                int totalSize = SZipHeader.Size
                                + compressedContentTable.Length
                                + compressedContentNameTable.Length
                                + compressedContentDataTableSize;

                byte[] output = new byte[totalSize];

                using (MemoryStream stream = new MemoryStream(output))
                {
                    using (BinaryWriter writer = new BinaryWriter(stream))
                    {
                        //ヘッダ
                        header.Write(writer);

                        //コンテンツ
                        writer.Write(compressedContentTable);

                        //コンテンツ名
                        writer.Write(compressedContentNameTable);

                        //データ
                        foreach (var data in compressedContentDataTable)
                        {
                            writer.Write(data);
                        }
                    }
                }

                return(output);
            }
        }
Beispiel #25
0
 public static byte[] CompressBytes(string input)
 {
     byte[] output = ZlibStream.CompressString(input);
     return(output);
 }
Beispiel #26
0
 /// <summary>
 /// Compress plain text to byte array
 /// </summary>
 public static byte[] Compress(string text)
 {
     return(ZlibStream.CompressString(text));
 }
Beispiel #27
0
        private static byte[] EncodeAndCompressRpcRequest(RpcRequest request)
        {
            string encodedRequest = Rencode.Encode(new object[] { request.RequestId, request.Method, request.Arguments.ToArray(), request.KeyWordArguments });

            return(ZlibStream.CompressString(encodedRequest));
        }
Beispiel #28
0
 public static byte[] CompressBytes(string input)
 {
     return(ZlibStream.CompressString(input));
 }