LZ4.Sharp 1.0.1905181345

dotnet add package LZ4.Sharp --version 1.0.1905181345                
NuGet\Install-Package LZ4.Sharp -Version 1.0.1905181345                
此命令旨在在 Visual Studio 的包管理器控制台中使用,因为它使用了 NuGet 模块的 Install-Package 版本。
<PackageReference Include="LZ4.Sharp" Version="1.0.1905181345" />                
对于支持 PackageReference 的项目,将此 XML 节点复制到项目文件中以引用此包。
paket add LZ4.Sharp --version 1.0.1905181345                
#r "nuget: LZ4.Sharp, 1.0.1905181345"                
#r 指令可以用于 F# Interactive 和 Polyglot Notebooks。将此内容复制到交互式工具或脚本源代码中以引用此包。
// Install LZ4.Sharp as a Cake Addin
#addin nuget:?package=LZ4.Sharp&version=1.0.1905181345

// Install LZ4.Sharp as a Cake Tool
#tool nuget:?package=LZ4.Sharp&version=1.0.1905181345                

LZ4.Sharp

关于

用于支持多种压缩模式和数据解压缩的 LZ4 的 C# 封装。

GitHub Nuget

方法

/// <summary>
/// Compress a given array of bytes, storing the result within the 'out' variable 'compressedData'.
/// The compression is completed respected the settings provided.
/// </summary>
/// <param name="data">The data you want to compress using LZ4.</param>
/// <param name="compressedData">The compressed representation of the data, null if the result is not 'Success'.</param>
/// <param name="settings">The settings to use when compressing the provided data.</param>
/// <returns>An LZ4Result stating the result of the compression.</returns>
public static LZ4Result CompressBytes(byte[] data, out byte[] compressedData, LZ4CompressionSettings settings)
/// <summary>
/// Compress a string, storing the result within the 'out' variable 'compressedData'.
/// The compression is completed respected the settings provided.
/// </summary>
/// <param name="data">The string you want to compress using LZ4.</param>
/// <param name="compressedData">The compressed representation of the data, null if the result is not 'Success'.</param>
/// <param name="settings">The settings to use when compressing the provided data.</param>
/// <returns>An LZ4Result stating the result of the compression.</returns>
public static LZ4Result CompressString(string data, out byte[] compressedData, LZ4CompressionSettings settings)
/// <summary>
/// Compress a given stream, storing the result within the 'out' variable 'compressedData'.
/// The compression is completed respected the settings provided.
/// </summary>
/// <param name="stream">The stream you want to compress using LZ4.</param>
/// <param name="compressedData">The compressed representation of the data, null if the result is not 'Success'.</param>
/// <param name="settings">The settings to use when compressing the provided data.</param>
/// <returns>An LZ4Result stating the result of the compression.</returns>
public static LZ4Result CompressStream(Stream stream, out byte[] compressedData, LZ4CompressionSettings settings)
/// <summary>
/// Decompress an array of compressed data, storing the result within the 'out' variable 'data'.
/// </summary>
/// <param name="compressedData">The source compressed data to be decompressed.</param>
/// <param name="uncompressedDataSize">The expected size of the decompressed data.</param>
/// <param name="data">[out] If decompression is successful the decompressed data, else null.</param>
/// <returns>An LZ4Result stating the result of the decompression.</returns>
public static LZ4Result DecompressBytes(byte[] compressedData, int uncompressedDataSize, out byte[] data)
/// <summary>
/// Decompress a stream of compressed data, storing the result within the 'out' variable 'data'.
/// </summary>
/// <param name="compressedData">The source compressed data to be decompressed.</param>
/// <param name="uncompressedDataSize">The expected size of the decompressed data.</param>
/// <param name="data">[out] If decompression is successful the decompressed data, else null.</param>
/// <returns>An LZ4Result stating the result of the decompression.</returns>

示例

const int randomDataSize = 1024 * 512;
var dataToCompress = new byte[randomDataSize];

// Generate some random data for our data source
var random = new Random();
for (var offset = 0; offset < randomDataSize; ++offset)
{
	dataToCompress[offset] = (byte)random.Next('A', 'E');
}

foreach (var compressionSetting in new[]
	{
		LZ4CompressionSettings.Fast,
		LZ4CompressionSettings.Default,
		LZ4CompressionSettings.Ultra
	})
{
	var start = DateTime.Now;
	// Compress the data
	var result = LZ4Sharp.CompressBytes(dataToCompress, out var compressedData, compressionSetting);
	if (result != LZ4Result.Success)
	{
		Console.WriteLine($"Failed to compress data using settings {compressionSetting}, Reason: {result}.");
		continue;
	}

	// Output the results
	var length = DateTime.Now - start;
	Console.WriteLine($"Compressed {dataToCompress.Length} bytes down to {compressedData.Length} bytes using settings {compressionSetting} [Time {length}].");
}

Console.WriteLine();
Console.WriteLine("Complete");
Console.ReadLine();
// Output:
/*
Compressed 524288 bytes down to 296705 bytes using settings Mode: Fast, Level: Default [Time 00:00:00.2922018].
Compressed 524288 bytes down to 207683 bytes using settings Mode: HighQuality, Level: Default [Time 00:00:03.9848956].
Compressed 524288 bytes down to 195994 bytes using settings Mode: HighQuality, Level: Max [Time 00:00:03.4059679].
*/
产品 兼容和额外的计算目标框架版本。
.NET Framework net45 兼容。 net451 已计算。 net452 已计算。 net46 已计算。 net461 已计算。 net462 已计算。 net463 已计算。 net47 已计算。 net471 已计算。 net472 已计算。 net48 已计算。 net481 已计算。
兼容的目标框架
包含的目标框架(在包中)
了解有关目标框架.NET标准的更多信息。

此包没有依赖项。

NuGet包

此包未被任何NuGet包使用。

GitHub存储库

此包未被任何流行的GitHub存储库使用。

版本 下载 最后更新
1.0.1905181345 1,071 5/18/2019
1.0.0 571 5/16/2019

首次发布