当前位置:网站首页>Compressed string
Compressed string
2022-07-24 18:51:00 【dustdone】
Namespace :
using System.IO;
using System.IO.Compression;
// Compress
public static byte[] Compress(byte[] data)
{
try
{
MemoryStream ms = new MemoryStream();
GZipStream zip = new GZipStream(ms, CompressionMode.Compress, true);
zip.Write(data, 0, data.Length);
zip.Close();
byte[] buffer = new byte[ms.Length];
ms.Position = 0;
ms.Read(buffer, 0, buffer.Length);
ms.Close();
return buffer;
}
catch (Exception e)
{
throw new Exception(e.Message);
}
}
// decompression
public static byte[] Decompress(byte[] data)
{
try
{
MemoryStream ms = new MemoryStream(data);
GZipStream zip = new GZipStream(ms, CompressionMode.Decompress, true);
MemoryStream msreader = new MemoryStream();
byte[] buffer = new byte[0x1000];
while (true)
{
int reader = zip.Read(buffer, 0, buffer.Length);
if (reader <= 0)
{
break;
}
msreader.Write(buffer, 0, reader);
}
zip.Close();
ms.Close();
msreader.Position = 0;
buffer = msreader.ToArray();
msreader.Close();
return buffer;
}
catch (Exception e)
{
throw new Exception(e.Message);
}
}
边栏推荐
- 深度学习中Dropout原理解析
- Nacos introduction and console service installation
- Pam4 popular science
- Type-C PD protocol chip while charging and listening
- Leetcode memory deep search / dynamic planning V2
- Generate publickey with der format public key and report an error
- Ionic4 Learning Notes 6 -- using native ionic4 components in custom components
- The problem that files cannot be uploaded to the server using TFTP is solved
- 使用 tftp 无法向服务器上传文件问题解决
- 字符串的遍历及拼接
猜你喜欢

Data analysis of network security competition of national vocational college skills competition digital forensics-a

Windowing function (1) - top three employees of department salary

FPGA 20 routines: 9. DDR3 memory particle initialization write and read through RS232 (Part 1)

04-分布式资源管理系统YARN

狂神redis笔记11

L4l7 load balancing

Ionic4 learning notes 8 -- UI component 2 list (no practice, direct excerpt)

Easily learn pytoch transfer learning to realize surface defect inspection

Cryptography knowledge - Introduction to encryption -1

OPENGL学习(四)GLUT三维图像绘制
随机推荐
Common problems of multithreading and concurrent programming (to be continued)
Introduction to nipple music theory and personal perception
OPENGL学习(二)OPENGL渲染管线
Type-C边充边听PD协议芯片
Mysql数据库,去重,连接篇
Vsftpd2.3.4-端口渗透 6200 irc_3281_backdoor
What are the benefits of knowledge management in enterprises?
OpenGL learning (II) opengl rendering pipeline
TCL programming style guide
core dump
L4l7 load balancing
redis 数据类型
Attack and defense world novice zone PWN
Nftscan and port3 have reached strategic cooperation in the field of NFT data
关于core文件
leetcode-记忆化深搜/动态规划v2
Rookie colleagues cost me 2K. Did you recite the secret of salary increase? (collect it quickly!)
Cryptography knowledge - Introduction to encryption -1
狂神redis笔记11
Inoic4 learning notes 2