Skip to content

SharpGrip/FileSystem

Repository files navigation

SharpGrip FileSystem NuGet

Builds

FileSystem [Build]

Quality Gate Status
Maintainability Rating
Reliability Rating
Security Rating
Coverage

Introduction

SharpGrip FileSystem is a versatile .NET file system abstraction that supports multiple storage adapters. It empowers developers to manage various file systems and services through a unified and easily comprehensible API. By coding against the abstractions provided by this library, developers can sidestep vendor-specific APIs, effectively avoiding vendor lock-ins. This flexibility enhances the portability and maintainability of the codebase, allowing for smoother transitions between different file systems.

Installation

Reference NuGet package SharpGrip.FileSystem (https://www.nuget.org/packages/SharpGrip.FileSystem).

For adapters other than the local file system (included in the SharpGrip.FileSystem package) please see the Supported adapters section.

Supported adapters

Adapter Package NuGet
Local adapter SharpGrip.FileSystem NuGet NuGet
AmazonS3 SharpGrip.FileSystem.Adapters.AmazonS3 NuGet NuGet
AzureBlobStorage SharpGrip.FileSystem.Adapters.AzureBlobStorage NuGet NuGet
AzureFileStorage SharpGrip.FileSystem.Adapters.AzureFileStorage NuGet NuGet
Dropbox SharpGrip.FileSystem.Adapters.Dropbox NuGet NuGet
FTP SharpGrip.FileSystem.Adapters.Ftp NuGet NuGet
GoogleCloudStorage SharpGrip.FileSystem.Adapters.GoogleCloudStorage NuGet NuGet
GoogleDrive SharpGrip.FileSystem.Adapters.GoogleDrive NuGet NuGet
MicrosoftOneDrive SharpGrip.FileSystem.Adapters.MicrosoftOneDrive NuGet NuGet
SFTP SharpGrip.FileSystem.Adapters.Sftp NuGet NuGet

Supported operations

For a full list of the supported operations please see the IFileSystem interface.

Usage

Instantiation

var adapters = new List<IAdapter>
{
    new LocalAdapter("adapterPrefix", "adapterRootPath")
};

// Instantiation option 1.
var fileSystem = new FileSystem(adapters);

// Instantiation option 2.
var fileSystem = new FileSystem();
fileSystem.Adapters = adapters;

Local adapter

var adapters = new List<IAdapter>
{
    new LocalAdapter("local1", "/var/files"),
    new LocalAdapter("local2", "D:\\Files")
};

var fileSystem = new FileSystem(adapters);

Example operations

// Azure connection.
var azureClient = new ShareClient("connectionString", "shareName");

// Dropbox connection.
var dropboxClient = new DropboxClient("oAuth2AccessToken");

var adapters = new List<IAdapter>
{
    new LocalAdapter("local", "/var/files"),
    new AzureFileStorageAdapter("azure", "/Files", azureClient),
    new DropboxAdapter("dropbox", "/Files", dropboxClient)
};

// Copies a file from the `local` adapter to the `azure` adapter.
await fileSystem.CopyFileAsync("local://foo/bar.txt", "azure://bar/foo.txt");

// Moves a file from the `azure` adapter to the `dropbox` adapter.
await fileSystem.MoveFileAsync("azure://Foo/Bar.txt", "dropbox://Bar/Foo.txt");

// Writes string contents to the `azure` adapter.
await fileSystem.WriteFileAsync("azure://Foo.txt", "Bar!");

// Reads a text file from the `dropbox` adapter.
var contents = fileSystem.ReadTextFileAsync("dropbox://Foo.txt");