public byte[] GetBuffer(bool compress) { lock (this) { return(compress ? GZipUtil.Compress(FileUtil.GetFileBuffer(m_FileName)) : FileUtil.GetFileBuffer(m_FileName)); } }
public static byte[] DataToBytes(object data, DataSerializerConfig config, out byte flag) { byte[] bytes = null; flag = 0; using (MemoryStream ms = new MemoryStream()) { BinaryFormatter bf = new BinaryFormatter(); bf.Serialize(ms, data); bytes = ms.ToArray(); #if ENABLE_COMPRESS_SERIALIZE_DATA if (config.EnableCompression) { bytes = GZipUtil.Compress(bytes); flag |= (byte)Flags.Compress; } #endif if (config.CryptKey != null) { bytes = CryptoUtil.Encrypt(bytes, config.CryptKey, config.CryptIv); flag |= (byte)Flags.Crypt; } } return(bytes); }
byte[] AcquireAudioBufferData() { byte[] audio = null; try { lock (audioBuffer) { if (audioBuffer.Count > 0) { audio = audioBuffer.ToArray(); audioBuffer.Clear(); } } if (audio != null) { audio = GZipUtil.Compress(audio); return(audio); } return(null); } catch (Exception) { return(null); } }
public void Save(Action onComplete = null) { string path = WorldStateSavePath; File.WriteAllBytes(path, GZipUtil.Compress(_state.ToString())); Debug.Log($"saved WorldState data to {path}"); onComplete?.Invoke(); }
private void btnGZipUtil_Click(object sender, EventArgs e) { //压缩解压缩文本内容 string zippedContent = GZipUtil.Compress("wuhuacong"); string original = GZipUtil.Decompress(zippedContent); GZipUtil.Compress(Application.StartupPath, Application.StartupPath, "cityroad.zip"); GZipUtil.Decompress(Application.StartupPath, Path.Combine(Application.StartupPath, "cityroad"), "cityroad.zip"); MessageDxUtil.ShowTips("操作完成"); }
void AdHocDesktopThreadHandler() { Rectangle captureRectangle = Screen.PrimaryScreen.Bounds; //Rectangle captureRectangle = new Rectangle(0, 0, 240, 180); perviousBuffer = AllocateBuffer(captureRectangle); byte[] compressedBuffer = GZipUtil.Compress(perviousBuffer); user.Send(new AdHocDesktop_TcpObject(AdHocDesktop_TcpCommand.ProfileScreen, profile.Src, profile.Dest, captureRectangle.Size)); user.Send(new AdHocDesktop_TcpObject(AdHocDesktop_TcpCommand.StreamingScreen, profile.Src, profile.Dest, compressedBuffer)); while (isRunning) { try { if (isNextNewCapture) { isNextNewCapture = false; perviousBuffer = null; } byte[] currentBuffer = AllocateBuffer(captureRectangle); //currentBuffer = ImageUtil.TransformHSV(currentBuffer); if (perviousBuffer != null) { byte[] comparedBuffer = ImageUtil.CompareImage(perviousBuffer, currentBuffer); compressedBuffer = GZipUtil.Compress(comparedBuffer); } else { compressedBuffer = GZipUtil.Compress(currentBuffer); } user.Send(new AdHocDesktop_TcpObject(AdHocDesktop_TcpCommand.StreamingScreen, profile.Src, profile.Dest, compressedBuffer)); perviousBuffer = currentBuffer; Thread.Sleep(500); } catch (Exception e) { MessageBox.Show(e.ToString()); } } }
public byte[] Serialize <TObject>(TObject obj) { if (obj == null) { return(new byte[0]); } byte[] data = Encoding.UTF8.GetBytes(_jsonSerializer.Serialize(obj)); if (data.Length > NTKeyword.IntK) // 因为设计了_heade,这个值是可以改的 { data = GZipUtil.Compress(data); byte[] array = new byte[_head.Length + data.Length]; _head.CopyTo(array, 0); data.CopyTo(array, _head.Length); return(array); } else { return(data); } }
void SendStreaming(AdHocDesktop_TcpClient client, byte[] buffer, AdHocDesktop_TcpCommand command) { bandwidthInput += (buffer == null ? 0 : buffer.Length); List <AdHocDesktop_TcpClient> groups = groupTable[client.Identifier]; for (int i = 0; i < groups.Count; i++) { if (!groups[i].IsConnected) { groups.RemoveAt(i); i--; } } for (int i = 0; i < groups.Count; i++) { AdHocDesktop_TcpClient dest = groups[i]; if (winceClients.Contains(dest.Identifier)) { Size size = new Size(240, 180); if (command == AdHocDesktop_TcpCommand.StreamingCamera) { using (Bitmap b = ImageUtil.ByteToBitmap(buffer)) { buffer = ImageUtil.ResizeBitmapToJpegByte(b, size); } } else if (command == AdHocDesktop_TcpCommand.StreamingScreen) { using (Bitmap b = ImageUtil.ByteToBitmap(GZipUtil.Decompress(buffer))) { buffer = GZipUtil.Compress(ImageUtil.ResizeBitmapToByte(b, size)); } } } dest.Send(new AdHocDesktop_TcpObject(command, client.Identifier, dest.Identifier, buffer)); bandwidthOutput += (buffer == null ? 0 : buffer.Length); } }
private void Create_impl(byte[] buffer) { byte[] bytes = GZipUtil.Compress(buffer); foreach (var pair in mProgramInfos) { PROGRAM program = pair.Key; ProgramInfo info = pair.Value; if (!info.Create) { continue; } info.CreateData(mStrFiler, info.Compress ? bytes : buffer); CreateTable(info); CreateCustom(DataClassName, mPackage, mFields, info, true); foreach (var custom in mCustoms) { CreateCustom(custom.Key, mPackage, custom.Value, info, false); } foreach (var custom in mEnums) { info.CreateFile(custom.Key, info.GenerateEnum.Generate(custom.Key, mPackage, custom.Value)); } } }
public static void DealerSend(this DealerSocket socket, KeyData kd) { byte[] zipData = GZipUtil.Compress(kd.Data); socket.SendMoreFrameEmpty().SendMoreFrame(kd.Key).SendFrame(zipData); }