LZ4.Sharp 1.0.1905181345

dotnet add package LZ4.Sharp --version 1.0.1905181345                
NuGet\Install-Package LZ4.Sharp -Version 1.0.1905181345                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="LZ4.Sharp" Version="1.0.1905181345" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add LZ4.Sharp --version 1.0.1905181345                
#r "nuget: LZ4.Sharp, 1.0.1905181345"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// 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

About

A C# wrapper for LZ4, supporting multiple compression modes and decompression of data.

GitHub Nuget

Methods

/// <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>

Example

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].
*/
Product Compatible and additional computed target framework versions.
.NET Framework net45 is compatible.  net451 was computed.  net452 was computed.  net46 was computed.  net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.1905181345 1,132 5/18/2019
1.0.0 594 5/16/2019

Initial Release