KristofferStrube.Blazor.CompressionStreams 0.1.0

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

// Install KristofferStrube.Blazor.CompressionStreams as a Cake Tool
#tool nuget:?package=KristofferStrube.Blazor.CompressionStreams&version=0.1.0                

License: MIT GitHub issues GitHub forks GitHub stars

NuGet Downloads (official NuGet)

Introduction

A Blazor wrapper for the browser API Compression Streams

The API defines way to compress and decompress streams of binary data. This project implements a wrapper around the API for Blazor so that we can easily and safely compress and decompress streams.

Demo

The sample project can be demoed at https://kristofferstrube.github.io/Blazor.CompressionStreams/

On each page you can find the corresponding code for the example in the top right corner.

On the API Coverage Status page you can see how much of the WebIDL specs this wrapper has covered.

Getting Started

The package can be used in Blazor projects.

Prerequisites

You need to install .NET 7.0 or newer to use the library.

Download .NET 7

Installation

You can install the package via Nuget with the Package Manager in your IDE or alternatively using the command line:

dotnet add package KristofferStrube.Blazor.CompressionStreams

Import

You need to reference the package in order to use it in your pages. This can be done in _Import.razor by adding the following.

@using KristofferStrube.Blazor.CompressionStreams

Creating wrapper instance

You can create wrapper instances for CompressionStream and DecompressionStream with the two following sets of constructors which either take a format or a reference to an existing JS CompressionStream.

// Compression Stream constructions
var newCompressionStream = await CompressionStream.CreateAsync(JSRuntime, CompressionAlgorithm.Deflate);

IJSObjectReference jSCompressionStream;
var existingCompressionStream = await CompressionStream.CreateAsync(JSRuntime, jSCompressionStream);

// Decompression Stream constructions
var newDecompressionStream = await DecompressionStream.CreateAsync(JSRuntime, CompressionAlgorithm.Deflate);

IJSObjectReference jSDecompressionStream;
var existingDecompressionStream = await DecompressionStream.CreateAsync(JSRuntime, jSDecompressionStream);

Using CompressionStream and DecompressionStream

The primary usage of the CompressionStreams and DecompressionStreams are in combination with the Blazor.Streams library where the ReadableStream can be piped through any stream that implements the IGenericTransformStream interface which both CompressionStream and DecompressionStream does.

ReadableStream readableStream;

ReadableStream compressed = await readableStream.PipeThroughAsync(newCompressionStream);

ReadableStream decompressed = await compressed.PipeThroughAsync(newDecompressionStream);

This can be useful if you have limited bandwidth and want to stream some content.

Issues

Feel free to open issues on the repository if you find any errors with the package or have wishes for features.

This repository was build with inspiration and help from the following series of articles:

Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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

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
0.1.0 270 3/16/2023
0.1.0-alpha.1 98 3/15/2023
0.1.0-alpha.0 86 3/14/2023