当前位置:网站首页>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
边栏推荐
猜你喜欢
随机推荐
关于 SAP 电商云 Spartacus UI SSR 的 state transfer 问题
vim clear last search highlighting
dotnet 删除只读文件
括号匹配
web漏洞扫描器-awvs
QT(42)-QT线程-线程调用槽函数
dotnet enables JIT multi-core compilation to improve startup performance
Red5搭建直播平台
Zynq Fpga图像处理之AXI接口应用——axi_lite接口使用
[Academic related] Tsinghua professor persuaded to quit his Ph.D.:I have seen too many doctoral students have mental breakdowns, mental imbalances, physical collapses, and nothing!...
3、IO流之字节流和字符流
idea2021版本添加上一步和下一步操作到工具栏
Tear down the underlying mechanism of the five JOINs of SparkSQL
moke、动态图片资源打包显示
STP --- 生成树协议
动态规划_双数组字符串
vs Code 运行一个本地WEB服务器
Using Baidu EasyDL to realize forest fire early warning and identification
该如何训练好深度学习模型?
C语言之实现扫雷小游戏









