当前位置:网站首页>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
边栏推荐
- Zynq Fpga图像处理之AXI接口应用——axi_lite接口使用
- 路由中的meta、params传参的一些问题(可传不可传,为空,搭配,点击传递多次参数报错)
- bracket matching
- 顺序队列
- [2022 Nioke Duo School 5 A Question Don't Starve] DP
- visual studio 2015 warning MSB3246
- [21天学习挑战赛——内核笔记](二)——设备树基础
- 3. Byte stream and character stream of IO stream
- 【一起学Rust | 进阶篇 | Service Manager库】Rust专用跨平台服务管理库
- C语言小笔记+题
猜你喜欢
After the tester with 10 years of service "naked resignation" from the big factory...
文章复现:超分辨率网络-VDSR
mdk5.14无法烧录
proe和creo的区别有哪些
Zynq Fpga图像处理之AXI接口应用——axi_lite接口使用
【PCBA方案设计】握力计方案
[TypeScript] In-depth study of TypeScript enumeration
项目难管理?先学会用好甘特图(内附操作方法及实用模板)
Retrofit的使用及原理详解
【2022杭电多校5 1012题 Buy Figurines】STL的运用
随机推荐
mdk5.14无法烧录
[2022 Hangzhou Electric Multi-School 5 1003 Slipper] Multiple Super Source Points + Shortest Path
Oreo域名授权验证系统v1.0.6公益开源版本网站源码
LINQ to SQL (Group By/Having/Count/Sum/Min/Max/Avg操作符)
在vs code中进行本地调试和开启本地服务器
拒绝服务攻击DDoS介绍与防范
【2022杭电多校5 1012题 Buy Figurines】STL的运用
Web3安全风险令人生畏,应该如何应对?
Data warehouse (1) What is data warehouse and what are the characteristics of data warehouse
PowerCLi 导入License到vCenter 7
基于单向链表结构的软件虚拟定时器的设计与构建
三种方式设置特定设备UWP XAML view
工龄10年的测试员从大厂“裸辞”后...
帝国CMS仿核弹头H5小游戏模板/92game帝国CMS内核仿游戏网整站源码
数字IC设计中基本运算的粗略的延时估计
【1403. 非递增顺序的最小子序列】
Zynq Fpga图像处理之AXI接口应用——axi_lite接口使用
C语言小笔记+题
for 循环中的 ++i 与 i++
Qt Designer生成的图形可以自适应窗口的大小变化