Skip to content

SmallBin is a lightweight, secure file storage library for .NET that enables storing multiple files in a single encrypted container with metadata support

License

Notifications You must be signed in to change notification settings

GarvinSchaub/SmallBin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

88 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

SmallBin

NuGet License: MIT

SmallBin is a lightweight, secure file storage library for .NET that enables storing multiple files in a single encrypted container with metadata support and comprehensive logging capabilities.

πŸ”‘ Key Features

  • Single-file encrypted database
  • Password-based encryption (AES-256)
  • File metadata and tagging
  • File compression support
  • Search functionality
  • Thread-safe operations
  • Flexible logging system with console and file output
  • Extensible logging interface

πŸ“¦ Installation

dotnet add package SmallBin

πŸš€ Quick Start

Creating a New Database

using SmallBin;
using SmallBin.Logging;

// Optional: Configure logging
var logger = new ConsoleLogger(); // or new FileLogger("app.log")

// Create or open an encrypted database using the builder pattern
using var db = SecureFileDatabase.Create("mydata.sdb", "password123")
    .WithoutCompression()  // Optional: disable compression (enabled by default)
    .WithAutoSave()       // Optional: enable auto-save (disabled by default)
    .WithLogger(logger)   // Optional: add logging support
    .Build();

// The builder pattern makes it clear which options are being configured
// and allows for future extensibility without breaking changes

Adding Files

// Add a single file with tags
db.SaveFile("document.pdf",
    tags: new List<string> { "work", "reports" },
    contentType: "application/pdf");

// Add multiple files
foreach (string file in Directory.GetFiles("source", "*.jpg"))
{
    db.SaveFile(file,
        tags: new List<string> { "photos" },
        contentType: "image/jpeg");
}

Retrieving Files

// Get file by ID
byte[] fileContent = db.GetFile(fileId);
File.WriteAllBytes("exported.pdf", fileContent);

Searching Files

// Search by filename
var criteria = new SearchCriteria { FileName = "report" };
var files = db.Search(criteria);

// Search by tags
var photoFiles = db.Search(new SearchCriteria 
{ 
    Tags = new List<string> { "photos" } 
});

Managing Metadata

db.UpdateMetadata(fileId, entry => 
{
    entry.Tags.Add("important");
    entry.CustomMetadata["author"] = "John Doe";
    entry.ContentType = "application/pdf";
});

Deleting Files

db.DeleteFile(fileId);

Configuring Logging

// Console logging
var consoleLogger = new ConsoleLogger();

// File logging
var fileLogger = new FileLogger("app.log");

// Custom logging by implementing ILogger
public class CustomLogger : ILogger
{
    public void Log(string message)
    {
        // Custom logging implementation
    }
}

// Using multiple loggers
var db = SecureFileDatabase.Create("mydata.sdb", "password123")
    .WithLogger(consoleLogger)
    .WithLogger(fileLogger)
    .Build();

Configuring Logging

// Console logging
var consoleLogger = new ConsoleLogger();

// File logging
var fileLogger = new FileLogger("app.log");

// Custom logging by implementing ILogger
public class CustomLogger : ILogger
{
    public void Log(string message)
    {
        // Custom logging implementation
    }
}

// Using multiple loggers
var db = SecureFileDatabase.Create("mydata.sdb", "password123")
    .WithLogger(consoleLogger)
    .WithLogger(fileLogger)
    .Build();

πŸ–₯️ WPF Application Example

public partial class MainWindow : Window
{
    private SecureFileDatabase _db;
    private ILogger _logger;

    private void OpenDatabase()
    {
        _logger = new FileLogger("app.log");
        _db = SecureFileDatabase.Create("data.sdb", "password123")
            .WithAutoSave() // Enable auto-save for WPF applications
            .WithLogger(_logger)
            .Build();
    }

    private void AddFile_Click(object sender, RoutedEventArgs e)
    {
        var dialog = new OpenFileDialog { Multiselect = true };
        if (dialog.ShowDialog() == true)
        {
            foreach (string filename in dialog.FileNames)
            {
                _db.SaveFile(filename);
            }
        }
    }
}

πŸ”’ Security Considerations

  • Passwords should be strong and securely stored
  • Database files contain encrypted content
  • Each file has its own encryption IV
  • Uses PBKDF2 for key derivation
  • All operations are logged for security auditing

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ‘₯ Contributing

Contributions welcome! NEVER submit pull requests directly to the main branch.

Version Impact

Type Version Change When to Use
breaking: MAJOR (1.0.0) Incompatible API changes, removing features
major: MAJOR (1.0.0) Same as breaking
feat: MINOR (0.1.0) New features, capabilities, or enhancements
fix: PATCH (0.0.1) Bug fixes, correcting behavior
refactor: PATCH Code restructuring without behavior change
chore: PATCH Build process, dependencies, tooling
style: PATCH Code formatting, naming (no logic change)
test: PATCH Adding/modifying tests
docs: NONE Documentation only
ci: NONE CI/CD changes

Examples

breaking: remove support for XML config files
feat: add dark mode theme support
fix: prevent crash when user input is empty
chore: update NuGet packages
refactor: simplify login logic
style: fix code indentation
test: add unit tests for auth service
docs: update API documentation
ci: add new deploy stage

Additional Tips

  • Use present tense ("add feature" not "added feature")
  • Keep first line under 70 characters
  • Add scope for clarity: feat(auth):, fix(db):
  • Include ticket number if needed: feat: add login (#123)

⭐ Show Your Support

If you find this project useful, please consider giving it a star on GitHub!

Star History Chart