Thank you for your interest in contributing to FileTypeChecker! This document provides guidelines for contributing to this .NET library for file type validation using magic number detection.
- .NET SDK 6.0 or later
- Git
-
Fork and clone the repository:
git clone https://github.com/yourusername/FileTypeChecker.git cd FileTypeChecker -
Build the project:
dotnet build
-
Run tests to ensure everything works:
dotnet test
- Build the library:
dotnet build - Run all tests:
dotnet test - Run async tests only:
dotnet test --filter "FileTypeValidatorAsyncTests|StreamExtensionsAsyncTests" - Test the sample app:
cd Samples/FileTypeChecker.App dotnet run
- Follow standard C# coding conventions
- Use meaningful variable and method names
- Add XML documentation for all public APIs
- Maintain both synchronous and asynchronous API support
- Include appropriate unit tests for new functionality
To add support for a new file type:
- Create a new class in
FileTypeChecker/Types/inheriting fromFileType - Implement the required magic sequences and validation logic
- Add both sync and async support
- Include comprehensive tests with sample files
- Update documentation if needed
Example:
public class MyFileType : FileType
{
public override string Name => "My File Format";
public override string[] Extensions => new[] { "myf" };
public override bool IsMatch(ReadOnlySpan<byte> data)
{
// Implementation
}
public override async Task<bool> IsMatchAsync(Stream stream, CancellationToken cancellationToken = default)
{
// Async implementation
}
}- Create an issue describing the bug
- Write a failing test that reproduces the issue
- Fix the bug
- Ensure all tests pass
- Submit a pull request
- Update XML documentation for public APIs
- Improve code comments for complex logic
- Update README or other documentation files as needed
- All new features must include comprehensive tests
- Tests should cover both synchronous and asynchronous APIs
- Include test files in
FileTypeChecker.Tests/files/for file type validation tests - Use descriptive test method names
- Test edge cases and error conditions
- Place test files in
FileTypeChecker.Tests/files/ - Use representative file samples for each supported format
- Keep test files small when possible
- Document any special test file requirements
- Fork the repository
- Create a feature branch from
master - Make your changes following the coding standards
- Add or update tests as appropriate
- Ensure all tests pass locally
- Update documentation if needed
- Submit a pull request with a clear description
- Use a descriptive title
- Provide a detailed description of changes
- Reference any related issues
- Include screenshots or examples if applicable
- Ensure CI checks pass
- All submissions require review
- Maintainers will provide feedback and may request changes
- Address feedback promptly
- Once approved, maintainers will merge the PR
- Keep file reading to a minimum (analyze only necessary bytes)
- Implement efficient byte comparison algorithms
- Consider memory allocation patterns
- Profile performance-critical code paths
- Maintain async/await best practices for non-blocking I/O
- Dual API Support: Provide both sync and async methods for all operations
- Performance: Minimize I/O operations and memory allocations
- FileTypeValidator: Main entry point for validation
- IFileType/FileType: Interface and base class for file type implementations
- MagicSequence: Binary signature representation
- StreamExtensions: Fluent validation methods
- Create an issue for bugs or feature requests
- Use discussions for questions about usage or contribution
- Check existing issues and documentation before asking questions
By contributing, you agree that your contributions will be licensed under the same license as the project.