当前位置:网站首页>dotnet compress Stream or file using lz4net
dotnet compress Stream or file using lz4net
2022-08-04 21:05:00 【Lin Dexi】
LZ4, a lossless compression algorithm, can be used in dotnet. The compression rate of this compression algorithm is not high but the speed is very fast.This library supports running on .NET Standard 1.6 .NET Core .NET Framework Mono Xamarin and UWP
The original code of the compression algorithm LZ4 is written in C, please see CodeK4os.Compression.LZ4 is written in C#, and there are also versions using C++ code
Because most of the time, Stream is compressed, so I will tell you how to compress Stream
Note that this compression algorithm is not zip or rar compression, that is, the compressed file cannot be opened with the current zip compression software, and the compressed content is not a file
Install using NuGetK4os.Compression.LZ4.Streams Simple to use LZ4 compression
If I need to compress a string to a file
using K4os.Compression.LZ4.Streams;using (var stream = LZ4Stream.Encode(File.Create("1.lz4"))){using (var sw = new StreamWriter(stream)){sw.WriteLine("Lin Dexi is funny");}}This compresses the string into the file
Calling LZ4Stream.Encode to pass in stream and writing to the returned stream will be compressed to the incoming stream as above
The decompression is the LZ4Stream.Decode method, such as decompressing the above file
using (var stream = new StreamReader(LZ4Stream.Decode(File.Open("1.lz4", FileMode.Open)))){Console.WriteLine(stream.ReadLine());}Run the code and you can find that the output is funny. This is the simple use of LZ4, in fact, the complex use is similar to the simple one
Parameters can also be passed in Encode and Decode to configure higher performance compression
lz4/lz4: Extremely Fast Compression algorithm
a>All code is in github
边栏推荐
- LayaBox---TypeScript---结构
- 【一起学Rust | 进阶篇 | Service Manager库】Rust专用跨平台服务管理库
- 链栈的应用
- idea2021版本添加上一步和下一步操作到工具栏
- 漫画 | 老板裁掉我两周后,又把我请回去,工资翻番!
- [Teach you to use the serial port idle interrupt of the STM32HAL library]
- Zero-knowledge proof - zkSNARK proof system
- 【1403. 非递增顺序的最小子序列】
- vim clear last search highlighting
- 【AGC】构建服务1-云函数示例
猜你喜欢

【TypeScript】深入学习TypeScript枚举

PowerCLi 导入License到vCenter 7

拒绝服务攻击DDoS介绍与防范

宝塔实测-搭建中小型民宿酒店管理源码

3. Byte stream and character stream of IO stream
![[2022 Hangzhou Electric Multi-School 5 1003 Slipper] Multiple Super Source Points + Shortest Path](/img/78/054329dec6a6faea5e9d583b6a8da5.png)
[2022 Hangzhou Electric Multi-School 5 1003 Slipper] Multiple Super Source Points + Shortest Path

帝国CMS仿核弹头H5小游戏模板/92game帝国CMS内核仿游戏网整站源码
![[Data Mining] Written Exam Questions for Sohu Data Mining Engineers](/img/d9/450eeecd5c7835d40ac38da41fc08e.png)
[Data Mining] Written Exam Questions for Sohu Data Mining Engineers

STP --- 生成树协议

面试官:Redis中过期的key是怎么被删除的?
随机推荐
vs Code 运行一个本地WEB服务器
win10 uwp 修改图片质量压缩图片
大资本已开始逃离加密领域?
拒绝服务攻击DDoS介绍与防范
About the state transfer problem of SAP e-commerce cloud Spartacus UI SSR
After encountering MapStruct, the conversion between PO, DTO and VO objects is no longer handwritten
格密码入门
proe和creo的区别有哪些
jekyll adds a flowchart to the blog
经验分享|盘点企业进行知识管理时的困惑类型
【debug】postgres数据存储错乱
MySQL field type
vim clear last search highlighting
xss课堂内容复现
for 循环中的 ++i 与 i++
链队
How to understand the crawler's Scrapy framework in the simplest and most popular way?
adb shell input keyevent 模拟按键事件
常用正则表达式[通俗易懂]
bracket matching