wan24-Compression 2.7.0

dotnet add package wan24-Compression --version 2.7.0
NuGet\Install-Package wan24-Compression -Version 2.7.0
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="wan24-Compression" Version="2.7.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add wan24-Compression --version 2.7.0
#r "nuget: wan24-Compression, 2.7.0"
#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 wan24-Compression as a Cake Addin
#addin nuget:?package=wan24-Compression&version=2.7.0

// Install wan24-Compression as a Cake Tool
#tool nuget:?package=wan24-Compression&version=2.7.0

wan24-Compression

This library exports a generic compression API, which allows to use any implemented compression algorithm to be applied using a simple interface.

The goals of this library are:

  • Make a choice being a less torture
  • Make a complex thing as easy as possible

Implementing (new) compression algorithms into (existing) code can be challenging. wan24-Compression tries to make it as easy as possible, while the API is still complex due to the huge number of options it offers.

How to get it

This library is available as NuGet package.

Usage

In case you don't use the wan24-Core bootstrapper logic, you need to initialize the library first, before you can use it:

wan24.Compression.Bootstrapper.Boot();

This will initialize the wan24-Compression library.

// Compress memory
byte[] compressed = uncompressed.Compress();
uncompressed = compressed.Decompress();

// Compress a stream
uncompressedStream.Compress(compressedStream, new()
{
    LeaveOpen = true
});
uncompressedStream.SetLength(0);
compressedStream.Decompress(uncompressedStream);

NOTE: The compressed output of this library may include a header, which can't (yet) be interpreted by any third party vendor code. That means, a compressed output of this library can't be decompressed with a third party compression library, even this library implements standard compression algorithms.

Using this library for a compressed sequence which has to be exchanged with a third party application, which relies on working with standard compression algorithm output, is not recommended - it may not work!

Anyway, this library should be a good choice for isolated use within your application(s), if want to avoid a hussle with implementing newer compression algorithms.

Decompression length limit

To avoid compressed bombs, which are tiny, but decompress to huge amounts of data, which may DoS your app, you should set a maximum for the uncompressed data size, if possible:

CompressionOptions options = new CompressionOptions()
    .WithMaxUncompressedDataLength(12345);// Limit to 12345 byte

This limits the decompressed data length effective, even if the uncompressed length is unknown.

NOTE: This limit won't affect compression and is being applied only for decompression! Anyway, it's a security task to set a decompression length limit.

JSON configuration

You could implement a JSON configuration file using the AppConfig logic from wan24-Core, and the CompressionAppConfig. There it's possible to define disabled algorithms, which makes it possible to react to an unwanted algorithm very fast, at any time and without having to update your app, for example. If you use an AppConfig, it could look like this:

public class YourAppConfig : AppConfig
{
    public YourAppConfig() : base() { }

    [AppConfig(AfterBootstrap = true)]
    public CompressionAppConfig? Compression { get; set; }
}

await AppConfig.LoadAsync<YourAppConfig>();

In the config.json in your app root folder:

{
    "Compression":{
        ...
    }
}

Anyway, you could also place and load a CompressionAppConfig in any configuration which supports using that custom type.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (4)

Showing the top 4 NuGet packages that depend on wan24-Compression:

Package Downloads
wan24-Crypto

Crypto helper

wan24-Compression-LZ4

LZ4 adoption for wan24-Compression

wan24-Compression-Shared-Tests

Shared tests for wan24-Compression libraries

wan24-I8N-Compressed

wan24-Core translation terms for the i8n compressed file format

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.7.0 98 4/28/2024
2.6.0 117 4/14/2024
2.5.0 210 3/9/2024
2.4.0 155 3/2/2024
2.3.0 179 2/24/2024
2.2.0 225 2/10/2024
2.1.0 133 1/20/2024
2.0.0 146 12/17/2023
1.20.2 237 11/11/2023
1.20.1 255 10/21/2023
1.20.0 248 10/15/2023
1.19.0 244 10/7/2023
1.18.0 185 9/27/2023
1.17.1 153 9/19/2023
1.17.0 200 9/19/2023
1.16.0 176 9/16/2023
1.15.0 200 9/10/2023
1.14.0 202 9/3/2023
1.13.1 230 7/30/2023
1.13.0 223 7/30/2023
1.12.0 303 7/22/2023
1.11.0 301 6/8/2023
1.10.1 266 6/3/2023
1.10.0 216 6/3/2023
1.9.0 228 5/29/2023
1.8.0 243 5/27/2023
1.7.0 252 5/20/2023
1.6.0 375 5/6/2023
1.5.0 321 5/1/2023
1.4.0 356 4/30/2023
1.3.0 313 4/29/2023
1.2.1 541 4/26/2023
1.2.0 256 4/25/2023
1.1.0 283 4/22/2023
1.0.0 215 4/17/2023