https://github.com/sparkeh9/Enchilada
Enchilada is a filesystem abstraction layer written in C#
https://github.com/sparkeh9/Enchilada
abstraction aspnetcore blob-storage dotnet-core filesystem ftp
Last synced: 7 months ago
JSON representation
Enchilada is a filesystem abstraction layer written in C#
- Host: GitHub
- URL: https://github.com/sparkeh9/Enchilada
- Owner: sparkeh9
- License: mit
- Created: 2016-08-28T14:08:51.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2018-11-01T09:56:59.000Z (about 7 years ago)
- Last Synced: 2025-04-04T16:44:25.226Z (8 months ago)
- Topics: abstraction, aspnetcore, blob-storage, dotnet-core, filesystem, ftp
- Language: C#
- Homepage:
- Size: 426 KB
- Stars: 29
- Watchers: 6
- Forks: 10
- Open Issues: 2
-
Metadata Files:
- Readme: Readme.md
- License: LICENSE
Awesome Lists containing this project
README
# Enchilada
[](https://ci.appveyor.com/api/projects/status/github/sparkeh9/enchilada?branch=master&svg=true)
## What is it?
Enchilada is a filesystem abstraction layer written in C#, the aim is to enable the seamless use of file operations over and between different providers.
Implemented:
- Local Filesystem - (local)
- Azure Blob Storage - (azure-blob)
- FTP/S - (ftp)
Planned:
- SCP (Secure Copy)
- AWS S3
## How to contribute
1. Fork
1. Hack!
1. Pull Request
### Nuget Packages
- https://www.nuget.org/packages/Enchilada/ - The main package, provides local filesystem support
- https://www.nuget.org/packages/Enchilada.Azure/ - Provides Azure blob storage
- https://www.nuget.org/packages/Enchilada.AspNetCore/ - Provides ASP.NET Core configuration support
- https://www.nuget.org/packages/Enchilada.Ftp/ - Provides FTP/S
## Usage
To reference a file, simply inject the filesystem resolver (`IEnchiladaFilesystemResolver`) into your code, which will normally be a single instance of `Enchilada.Infrastructure.EnchiladaFileProviderResolver`.
Once injected, simply pass in a URI (see below) to `IEnchiladaFilesystemResolver.OpenFileReference`, which will produce an instance of `IFile`, which represents the file on whatever platform your configuration specifies, regardless of whether it exists yet or not.
```C#
fileSystemResolver.OpenFileReference( "enchilada://blob_storage/image.jpg" );
```
The URI is made up of three parts:
- The scheme: Simply by convention this is normally `enchilada://`, but any such scheme can be specified
- The provider name: This mirrors the configurations you have specified in the appsettings file. It can be anything which looks like a valid URI hostname, however it must have a corresponding configuration.
- The path: as you might imagine, this is the path to the file.
### Saving a file from a stream
```C#
// Injected filesystem resolver
IEnchiladaFilesystemResolver enchilada;
var tempFile = new FileInfo( "C:\\test.png" );
using ( var filestream = tempFile.OpenReadStream() )
{
using ( var fileReference = enchilada.OpenFileReference( filepath ) )
{
await fileReference.CopyFromAsync( filestream );
}
}
```
## Local
The local adapter allows the resolution of files on the local filesystem or UNC path.
It does not currently handle connecting to resources which require authentication.
```json
"your_configuration_name": {
"adapter": "local",
"directory": "C:\\my-folder"
}
```
## Azure Blob
The Azure Blob (Binary Large Object) adapter allows the resolution of files on the azure service.
Authentication is handled via the connection string.
```json
"your_configuration_name": {
"adapter": "azure-blob",
"connectionString": "UseDevelopmentStorage=true;",
"containerReference": "test",
"createContainer": true,
"isPublicAccess": true
}
```
## FTP
The FTP adapter enables non-encrypted file transfer to a passive mode FTP server.
```json
"your_configuration_name": {
"adapter": "ftp",
"host": "ftp.github.com",
"port": "21",
"directory": "/sub/folder",
"username": "user@ftpserver.com",
"password": "$up3r.$3cur3.p4$$w0rd"
}
```
## AspNetCore configuration
**Enchilada.AspNetCore** comes with functionality to plumb your app settings configuration, straight
into the AspNetCore Dependency Injection framework. To configure, simply amend the `ConfigureServices` method
in `Startup.cs` as follows.
```C#
services.AddEnchilada( new EnchiladaBuilderOptions
{
Adapters = Configuration.GetSection( "Enchilada:Adapters" )
} );
```
And provide configuration in the appsettings file, e.g.
```json
{
"Enchilada": {
"Adapters": {
"local_filesystem": {
"adapter": "local",
"directory": "C:\\my-folder"
},
"blob_storage": {
"adapter": "azure-blob",
"connectionString": "UseDevelopmentStorage=true;",
"containerReference": "test",
"createContainer": true,
"isPublicAccess": true
}
}
}
}
```