PROWAREtech
.NET: Identify Brotli Compressed Files
See also: Identify GZip Files.
Determine if a file is compressed with the BrotliStream
class by reading the file's header bytes and checking for the specific Brotli signature. Brotli-compressed files have a unique "magic number" at the beginning: the first two bytes are 0xCE and 0xB2, which identify the file as being in Brotli format.
This approach is lightweight and allows for quickly verifying if a file is compressed with BrotliStream
without fully decompressing it.
NOTE: One can always try to decompress a Brolti-compressed file, and if it fails, then it is not a Brotli file.
Example Code
using System;
using System.IO;
public class Program
{
public static bool IsBrotliFile(string filePath)
{
// Open the file to check the header
using (var fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read))
{
if (fileStream.Length < 2)
{
return false; // File is too short to be a valid Brotli file
}
int byte1 = fileStream.ReadByte();
int byte2 = fileStream.ReadByte();
// Check for the Brotli signature (0xCE, 0xB2)
return byte1 == 0xCE && byte2 == 0xB2;
}
}
public static void Main()
{
string path = "file.br";
bool isBrotli = IsBrotliFile(path);
Console.WriteLine(isBrotli ? "The file is a Brotli-compressed file." : "The file is not a Brotli-compressed file.");
}
}
.
..
tutorial
.NET: About the System.Security.Cryptography Namespace
A general overview and explanation about hash, symmetric and asymmetric cryptography algorithms with examples available, like DES symmetric and RSA asymmetric algorithms; written in C#.
.NET: Access the Pixels of an Image Using SixLabors.ImageSharp v3.x
How to access each pixel's color information using SixLabors.ImageSharp, written in C#.
.NET: Add Comment to XML Document
Use the XmlSerializer and XmlDocument classes to add a comment to XML files; written in C#.
.NET: Alpha Compositing Algorithm
How to convert an image with an alpha channel to an image without an alpha channel; written in C#.
.NET: Call an External Function Using DllImport in C#
How to correctly use DllImport to call external functions in libraries on both windows (.dll files) and Linux (.so libraries).
.NET: CNN v1.0 for Supervised Deep Learning Example
An example one-dimensional and two-dimensional Convolutional Neural Network, deep learning library written in C#.
.NET: CNN v2.0 for Supervised Deep Learning Example
CNN version 2.0 is a full featured convolutional and recurrent neural network that supports embedding layers, gated recurrent unit (GRU) layers, batch normalization layers, neuron dropout layers and various pooling layers, and has full backpropagation throughout the network, including kernels/filters; this is designed for learning patterns in images, text, etc.; written in C#.
.NET: Common Activation Functions with Their Derivatives in C#
The neural network activation functions Rectified Linear Unit (ReLU), Leaky Rectified Linear Unit, Exponential Linear Unit (ELU), Hyperbolic Tangent (tanh), and Sigmoid with the derivates for each.
.NET: ConcurrentBag - What is It and How to Use It?
What a ConcurrentBag is plus example usage in C#.
.NET: ConcurrentDictionary - What is It and How to Use it?
What a ConcurrentDictionary is plus example usage in C#.
.NET: Convert a Binary Loss to a Percent Accuracy
How to convert a binary cross-entropy neural network loss value to an accuracy percentage (0-1); written in C#.
.NET: Convert a Softmax Loss to a Percentage Accuracy
How to convert a softmax cross-entropy neural network loss value to an accuracy percentage (0-1) for any number of classes or categories; written in C#.
.NET: Convert Dictionary Keys and Values to a List
How to create a list from either the keys or the values of a dictionary in C#.
.NET: Convert Double Array to Byte Array
How to use the BitConverter class to convert an array of doubles to an array of bytes and back again; written in C#.
.NET: Convert Float Array to Byte Array
How to use the BitConverter class to convert an array of floats to an array of bytes and back again; written in C#.
.NET: Convert Google's Gemini Markdown Text to HTML
A simple class to format Gemini text into HTML for viewing on the Internet; written in C#.
.NET: Convert Int Array to Byte Array
How to use the BitConverter class to convert an array of integers (int) to an array of bytes and back again; written in C#.
.NET: Convert Number to Binary String
How to convert a number such as an int, uint, long, ulong or other integer to a binary string using C#.
.NET: Copy Console Output to a Log File
How to copy the Console's output to a log file; written in C#.
.NET: Create, Read-from and Write-to the Process Class
Examples of creating processes and how to read console output and write to a console using the System.Diagnostics.Process class and use Windows Management Instrumentation (WMI) to create processes on remote machines; written in C# and VB.NET.
.NET: Crop Image to Square using SixLabors.ImageSharp v3.x
Use SixLabors.ImageSharp to crop an image to a square, written in C#.
.NET: Double to String Conversion Without Scientific Notation
How to print double values without using scientific notation, in C#.
.NET: Download any Type of File Data from a URL with HttpClient
Download a file from an Internet URL/URI using the HttpClient class; written in C#.
.NET: Extract the Page Title from HTML
How to find the title in an HTML page using regular expressions (RegEx) in C#.
.NET: Find Keywords in Text using Regex
How to find a keyword in text using C# and regular expressions.
.NET: Find the Index Value When Using LINQ Select()
How to know the current index value of an item when using the Language Integrated Query Select() method; example in C#.
.NET: Globally Unique Identifiers
The GUID is great for anything requiring uniqueness; examples in C# and VB.NET.
.NET: Google Generative AI Library
A simple library to access Google's generative AI processes; written in C#.
.NET: Hash-based Message Authentication Code
Safely store user passwords, written in C#.
.NET: How to Create WordPress Slugs
Use C# regular expressions (Regex) to create slugs with only standard characters for use in a URL or other purpose.
.NET: How to Randomize the Order of a List and Optional Parallel List
Using C#, randomize or shuffle a list, and optionally, a second, parallel list.
.NET: Identify Brotli Compressed Files
How to determine if a file is a Brotli compressed file (compressed with BrotliStream); written in C#.
.NET: Identify GZip Compressed Files
How to determine if a file is a GZip compressed file (compressed with GZipStream); written in C#.
.NET: Image Utility for SixLabors.ImageSharp v1.0
Manipulate images on Windows, Linux and MacOS machines including creating a scatter plot and histogram, and rotating the images as needed to display properly with a C# console application example.
.NET: Image Utility for SixLabors.ImageSharp v3.x
Manipulate images on Windows, Linux and MacOS machines including creating a scatter plot and histogram, and rotating the images as needed to display properly with a C# console application example.
.NET: Inverted Sigmoid Decay Function
A function that returns a value nearer to an initial value in the beginning then, as the input is nears the end, it begins to decrease its output; graphed it would be nearly straight until it would steeply decrease near the end.
.NET: Is a Number a Power of Two (2)
How to check or determine if a number has a base of 2 without using modulo operations for maximum performance; written in C#.
.NET: Join/Merge Two List, Array or Enumerable (IEnumerable) Objects
How to combine Lists, Arrays or Enumerables and, optionally, make them unique or distinct using C#.
.NET: K-Means Clustering Algorithm
Clustering code designed to group numerical data into bands or ranges; written in C#.
.NET: Kill or End a Process
How to terminate a process using C#.
.NET: Lazy Load Data
How to lazy load data using the C# programming language.
.NET: Machine Learning, Unsupervised Learning or Clustering, K-mean / Silhouette Clustering Library
An example of a machine learning library, or utility, written in C#.
.NET: Memory-Mapped Files
Memory-mapped files allow sharing large amounts of data between processes; they are explored here with examples in C#.
.NET: Mersenne Twister Random Number Generation
A popular Mersenne Twister pseudo random number generator example written in C#.
.NET: Multi-threading with Tasks
How to multi-thread using the Task class in C#.
.NET: Neural Network, Supervised Deep Machine Learning Example in C#
An example neural network, deep learning library written in C#; categorizes practically any data as long as it is properly normalized.
.NET: Nvidia CUDA for CSharp (v1.0.1 - Linux Edition)
Access Nvidia CUDA functionality from the C# language (as well as VB.NET) on a Linux x64 machine using this simple wrapper library.
.NET: Nvidia CUDA for CSharp (v1.0.1)
Access Nvidia CUDA functionality from the C# language (as well as VB.NET) on Windows 64-bit (x64) using this simple wrapper library.
.NET: Operating System Detection
How to detect if the operating system is Linux, MacOS or Windows using C#.
.NET: Power Status - AC/DC
How to detect the DC/battery operation or AC/plugged-in operation of the computer using C#.
.NET: Remove Data Outliers for Better Data
Remove data outliers using the Interquartile Range (IQR) method with logarithmic transformation; written in C#.
.NET: Retrieve the Executable's Path and Directory
How to find the .NET executable's path and directory using the C# programming language.
.NET: Reverse Geocode
Use latitude and longitude to reverse-geocode to country, US state/Canadian province and time zone in a .NET application all while offline; written in C#.
.NET: Sort a List of Objects with a Delegate Function
How to use a delegate to sort a C# List Holding Objects Instead of Primitive Types.
.NET: Strip/Remove HTML SCRIPT Tags from Text Using Regex
How to remove the SCRIPT tag and its containing code from HTML text using C# and regular expressions.
.NET: Strip/Remove HTML Tags from Text Using Regex
How to remove the tags from HTML text using C# and regular expressions.
.NET: The Random Class is Not Thread-safe!
How to use the Random class in a thread-safe manner to find reliable random values.
.NET: Use Callback Function with Windows API
How to use a callback function with the Windows API or any C/C++ DLL that exports a function requiring a callback function as a parameter in C#.
.NET: Using Brotli to Compress and Decompress Data
How to use the BrotliStream class to compress and decompress bytes, files or streams of data in C#.
.NET: Using GZip to Compress and Decompress Data
How to use the GZipStream class to compress and decompress bytes, files and streams of data in C#.
.NET: What's New or Changed in C# 6
A guide to the changes and additions in C# version 6.
.NET: What's New or Changed in C# 7
A guide to the changes and additions in C# version 7.
.NET: Working with Arrays
How to sort and work with parallel arrays in C#.
.NET: Working with Dates
Working with the Date object and the TimeSpan object written in C#.
.NET: Working with Strings
The StringBuilder class versus String.Format() plus common formatting parameters for dates and numbers written in C#.
.NET: Working with Threads
How to use the Thread class in C#.
.NET: XmlSerializer Example
Serialize and deserialize objects to XML strings using C#.