Table of Contents

FileIntegrityOptions Class

Definition

Namespace
Cuemon.Data.Integrity
Assemblies
Cuemon.Data.Integrity.dll
Source
src/Cuemon.Data.Integrity/FileIntegrityOptions.cs

Configuration options for FileInfo.

public class FileIntegrityOptions : FileInfoOptions, IParameterObject
Inheritance
object
FileIntegrityOptions
Implements
Inherited Members

Examples

The following example demonstrates how to use to configure file integrity checksum computation.

using System;
using System.IO;
using Cuemon.Data.Integrity;
using Cuemon.Security;

namespace MyApp.Examples
{
    public sealed class FileIntegrityOptionsExample
    {
        public void Demonstrate()
        {
            var defaults = new FileIntegrityOptions();
            Console.WriteLine($"Default bytes to read: {defaults.BytesToRead}");

            var path = Path.Combine(AppContext.BaseDirectory, "sample.dat");
            File.WriteAllText(path, "Hello, World!");

            try
            {
                IDataIntegrity integrity = DataIntegrityFactory.CreateIntegrity(new FileInfo(path), options =>
                {
                    options.BytesToRead = 8;
                    options.IntegrityConverter = (file, bytes) => new FilePreviewIntegrity(file.Name, bytes);
                });

                Console.WriteLine($"Checksum: {integrity.Checksum.ToHexadecimalString()}");
            }
            finally
            {
                if (File.Exists(path)) { File.Delete(path); }
            }
        }

        private sealed class FilePreviewIntegrity : IDataIntegrity
        {
            public FilePreviewIntegrity(string fileName, byte[] bytes)
            {
                FileName = fileName;
                Checksum = HashFactory.CreateFnv128().ComputeHash(bytes);
            }

            public string FileName { get; }

            public HashResult Checksum { get; }
        }
    }
}

Constructors

Name Description
FileIntegrityOptions()

Initializes a new instance of the FileIntegrityOptions class.

Properties

Name Description
IntegrityConverter

Gets or sets the function delegate that will convert an instance of FileInfo and a byte array into an object implementing the IDataIntegrity interface.