当前位置:网站首页>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
边栏推荐
猜你喜欢
推荐系统_刘老师
STP --- 生成树协议
经验分享|盘点企业进行知识管理时的困惑类型
LINQ to SQL (Group By/Having/Count/Sum/Min/Max/Avg操作符)
Retrofit的使用及原理详解
Uniapp微信雪糕刺客单页小程序源码
ts集成和使用
Tear down the underlying mechanism of the five JOINs of SparkSQL
js数据类型、节流/防抖、点击事件委派优化、过渡动画
Using Baidu EasyDL to realize forest fire early warning and identification
随机推荐
项目难管理?先学会用好甘特图(内附操作方法及实用模板)
大资本已开始逃离加密领域?
二叉搜索树解决硬木问题
遇到MapStruct后,再也不手写PO,DTO,VO对象之间的转换了
[Data Mining] Written Exam Questions for Sohu Data Mining Engineers
MySQL字段类型
matlab 画图
命名路由、组件中name的作用
Uniapp微信雪糕刺客单页小程序源码
How to carry out AI business diagnosis and quickly identify growth points for cost reduction and efficiency improvement?
数据仓库(1)什么是数据仓库,数仓有什么特点
经验分享|盘点企业进行知识管理时的困惑类型
Zero-knowledge proof notes - private transaction, pederson, interval proof, proof of ownership
Zynq Fpga图像处理之AXI接口应用——axi_lite接口使用
某男子因用本地虚拟机做压测,惨遭字节面试官当场嘲笑
win10 uwp 修改图片质量压缩图片
工龄10年的测试员从大厂“裸辞”后...
构建Buildroot根文件系统(I.MX6ULL)
在vs code中进行本地调试和开启本地服务器
五分钟入门文本处理三剑客grep awk sed