![]() |
VOOZH | about |
dotnet add package Blobject.Disk --version 5.0.19
NuGet\Install-Package Blobject.Disk -Version 5.0.19
<PackageReference Include="Blobject.Disk" Version="5.0.19" />
<PackageVersion Include="Blobject.Disk" Version="5.0.19" />Directory.Packages.props
<PackageReference Include="Blobject.Disk" />Project file
paket add Blobject.Disk --version 5.0.19
#r "nuget: Blobject.Disk, 5.0.19"
#:package Blobject.Disk@5.0.19
#addin nuget:?package=Blobject.Disk&version=5.0.19Install as a Cake Addin
#tool nuget:?package=Blobject.Disk&version=5.0.19Install as a Cake Tool
Blobject is a common, consistent storage interface for Microsoft Azure, Amazon S3, S3 compatible storage (i.e. Minio, Less3, View), CIFS (Windows file shares), NFS (Linux and UNIX file shares), Google Cloud Storage, and local filesystem written in C#.
| Library | Version | Downloads |
|---|---|---|
| Blobject.Core | 👁 NuGet Version |
👁 NuGet |
| Blobject.AmazonS3 | 👁 NuGet Version |
👁 NuGet |
| Blobject.AmazonS3Lite | 👁 NuGet Version |
👁 NuGet |
| Blobject.AzureBlob | 👁 NuGet Version |
👁 NuGet |
| Blobject.CIFS | 👁 NuGet Version |
👁 NuGet |
| Blobject.Disk | 👁 NuGet Version |
👁 NuGet |
| Blobject.GoogleCloud | 👁 NuGet Version |
👁 NuGet |
| Blobject.NFS | 👁 NuGet Version |
👁 NuGet |
If you have any issues or feedback, please file an issue here in Github. We'd love to have you help by contributing code for new features, optimization to the existing codebase, ideas for future releases, or fixes!
This project was built to provide a simple interface over external storage to help support projects that need to work with potentially multiple storage providers. It is by no means a comprehensive interface, rather, it supports core methods for creation, retrieval, deletion, metadata, and enumeration.
Though this library is MIT licensed, it is dependent upon other libraries, some of which carry a different license. Each of these libraries are included by reference, that is, none of their code has been modified.
| Package | URL | License |
|---|---|---|
| AWSSDK.S3 | https://github.com/aws/aws-sdk-net | Apache 2.0 |
| Azure.Storage.Blobs | https://github.com/Azure/azure-sdk-for-net | MIT |
| EzSmb | https://github.com/ume05rw/EzSmb | LGPL-3.0 |
| Google.Cloud.Storage.V1 | https://github.com/googleapis/google-cloud-dotnet | Apache 2.0 |
| SMBLibrary | https://github.com/TalAloni/SMBLibrary | LGPL-3.0 |
| NFS-Client | https://github.com/SonnyX/NFS-Client | Unknown, public |
| Nekodrive | https://github.com/nekoni/nekodrive | Unknown, public |
| S3Lite | https://github.com/jchristn/S3Lite | MIT |
BlobHelper to BlobjectS3Lite variant, not dependent on AWSSDKIEnumerable<BlobMetadata>, no pagination requiredBlobject.AmazonS3 and Blobject.AmazonS3Lite v5.0.19 normalize AWS region aliases such as USEast2 to DNS-safe names such as us-east-2 and default AWS S3 settings to HTTPSBlobject.Core v5.0.19 fixes streaming-first copy, bounded bulk operations, empty-write consistency, filter cloning, and case handlingWriteManyAsync and EmptyAsync behavior with configurable MaxConcurrencyRefer to the Test project for exercising the library.
The repository includes Touchstone-based automated contract tests. Test.Shared contains the runner-agnostic provider contract definitions. By default, the tests run against Blobject.Disk in a temporary directory and clean up after each case.
dotnet run --project src/Test.Automated/Test.Automated.csproj --framework net10.0
dotnet test src/Test.Xunit/Test.Xunit.csproj --framework net10.0
dotnet test src/Test.Nunit/Test.Nunit.csproj --framework net10.0
The default suite contains 80 contract cases. Add --include-stress true to Test.Automated to include large enumeration and large WriteManyAsync coverage.
dotnet run --project src/Test.Automated/Test.Automated.csproj --framework net10.0 -- --include-stress true
Test.Automated accepts provider-specific command-line overrides. Remote providers are isolated by a generated prefix and cleaned up by default.
dotnet run --project src/Test.Automated/Test.Automated.csproj --framework net10.0 -- \
--provider s3 \
--s3-access-key <access-key> \
--s3-secret-key <secret-key> \
--s3-region us-east-2 \
--s3-bucket <bucket> \
--prefix blobject-contract-tests
For S3-compatible storage, also supply --s3-endpoint, --s3-ssl, and --s3-base-url. Supported providers are disk, s3, s3lite, azure, gcp, cifs, and nfs; run Test.Automated --help for the full argument list. The xUnit and NUnit adapters use the same shared suite and can be configured with the equivalent BLOBJECT_TEST_* environment variables, such as BLOBJECT_TEST_PROVIDER, BLOBJECT_TEST_S3_BUCKET, and BLOBJECT_TEST_PREFIX.
dotnet test src/Test.Xunit/Test.Xunit.csproj --framework net10.0 \
-e BLOBJECT_TEST_PROVIDER=s3 \
-e BLOBJECT_TEST_S3_ACCESS_KEY=<access-key> \
-e BLOBJECT_TEST_S3_SECRET_KEY=<secret-key> \
-e BLOBJECT_TEST_S3_REGION=us-east-2 \
-e BLOBJECT_TEST_S3_BUCKET=<bucket>
The existing Test.* console applications remain available for interactive provider-specific testing.
using Blobject;
AwsSettings settings = new AwsSettings(
accessKey,
secretKey,
"us-west-1",
bucket);
BlobClient blobs = new BlobClient(settings);
AWS S3 region names are normalized against the current Amazon S3 regular endpoint region list. For example, USEast2, us_east_2, and us-east-2 are stored as us-east-2.
using Blobject.AmazonS3;
AwsSettings settings = new AwsSettings(
endpoint, // http://localhost:8000/
true, // enable or disable SSL
accessKey,
secretKey,
"us-west-1",
bucket,
baseUrl // i.e. http://localhost:8000/{bucket}/{key}
);
AmazonS3BlobClient blobs = new AmazonS3BlobClient(settings);
using Blobject.AmazonS3Lite;
// Initialize settings as above
AmazonS3LiteBlobClient blobs = new AmazonS3LiteBlobClient(settings);
For accessing public buckets that don't require authentication, you can omit the access key and secret key:
using Blobject.AmazonS3Lite;
// Anonymous access to a public bucket
AwsSettings settings = new AwsSettings(
null, // accessKey - null for anonymous access
null, // secretKey - null for anonymous access
"us-west-1",
"public-bucket-name"
);
AmazonS3LiteBlobClient blobs = new AmazonS3LiteBlobClient(settings);
// Check if credentials are configured
Console.WriteLine("Has credentials: " + settings.HasCredentials); // False
// Read operations work on public buckets
byte[] data = await blobs.GetAsync("public-file.txt");
Note: Write and delete operations require authentication. Anonymous access is read-only.
using Blobject.AzureBlob;
AzureBlobSettings settings = new AzureBlobSettings(
accountName,
accessKey,
"https://[accountName].blob.core.windows.net/",
containerName);
AzureBlobClient blobs = new AzureBlobClient(settings);
Important - you must have the JSON credentials for the service account, which includes the private key. Creation of these credentials requires the organization policy administrator role.
using Blobject.GoogleCloud;
GcpBlobSettings settings = new GcpBlobSettings(
projectId,
bucket,
"... JSON credentials for service account ..."
GcpBlobClient blobs = new GcpBlobClient(settings);
using Blobject.CIFS;
CifsSettings settings = new CifsSettings(
"localhost",
username,
password,
sharename);
CifsBlobClient blobs = new CifsBlobClient(settings);
using Blobject.Disk;
DiskSettings settings = new DiskSettings("blobs");
DiskBlobClient blobs = new DiskBlobClient(settings);
using Blobject.NFS;
NfsSettings settings = new NfsSettings(
"localhost",
0, // user ID
0, // group ID,
sharename,
NfsVersionEnum.V3 // V2, V3, or V4
);
NfsBlobClient = new NfsBlobClient(settings);
await blobs.WriteAsync("test", "text/plain", "This is some data"); // throws IOException
await blobs.WriteAsync("empty", "application/octet-stream", Array.Empty<byte>());
byte[] data = await blobs.GetAsync("test"); // throws IOException
bool exists = await blobs.ExistsAsync("test");
await blobs.DeleteAsync("test");
// Writing a file using a stream
FileInfo fi = new FileInfo(inputFile);
long contentLength = fi.Length;
using (FileStream fs = new FileStream(inputFile, FileMode.Open))
{
await _Blobs.WriteAsync("key", "content-type", contentLength, fs); // throws IOException
}
// Downloading to a stream
BlobData blob = await _Blobs.GetStreamAsync(key);
// read blob.ContentLength bytes from blob.Data
//
// Use a key of the form [path]/[to]/[file]/[filename].[ext]
//
await blobs.WriteAsync("subdirectory/filename.ext", "text/plain", "Hello!");
Enumeration is always full; the library will manage any continuation tokens (e.g. AWS S3, S3 compatible, Azure) and also recurse into subdirectories for file, CIFS, and NFS.
// Get BLOB metadata
BlobMetadata md = await _Blobs.GetMetadataAsync("key");
// Enumerate BLOBs
await foreach (BlobMetadata blob in _Blobs.EnumerateAsync())
Console.WriteLine(blob.Key + " " + blob.ContentLength + " folder? " + blob.IsFolder);
Enumeration filters are cloned internally so provider calls do not mutate caller-supplied filter instances. Object-storage providers use case-sensitive key matching; disk and CIFS use case-insensitive matching for compatibility with their typical filesystems.
If you have multiple storage repositories and wish to move BLOBs from one repository to another, use the BlobCopy class (refer to the Test.Copy project for a full working example).
Thanks to @phpfui for contributing code and the idea for this enhancement!
// instantiate two BLOB clients
BlobCopy copy = new BlobCopy(from, to);
CopyStatistics stats = await copy.StartAsync();
/*
{
"Success": true,
"Time": {
"Start": "2021-12-22T18:44:42.9098249Z",
"End": "2021-12-22T18:44:42.9379215Z",
"TotalMs": 28.1
},
"ContinuationTokens": 0,
"BlobsEnumerated": 12,
"BytesEnumerated": 1371041,
"BlobsRead": 12,
"BytesRead": 1371041,
"BlobsWritten": 12,
"BytesWritten": 1371041,
"Keys": [
"filename.txt",
...
]
}
*/
BlobCopy.Start(...) remains available for compatibility and delegates to StartAsync(...). Copy now uses GetStreamAsync and stream writes where the provider supports them.
WriteManyAsync and EmptyAsync use bounded concurrency through BlobClientBase.MaxConcurrency, which defaults to 4.
blobs.MaxConcurrency = 8;
await blobs.WriteManyAsync(writes);
Refer to CHANGELOG.md for version history.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 net5.0 was computed. net5.0-windows net5.0-windows was computed. net6.0 net6.0 was computed. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 is compatible. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
| .NET Core | netcoreapp3.0 netcoreapp3.0 was computed. netcoreapp3.1 netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.1 netstandard2.1 is compatible. |
| MonoAndroid | monoandroid monoandroid was computed. |
| MonoMac | monomac monomac was computed. |
| MonoTouch | monotouch monotouch was computed. |
| Tizen | tizen60 tizen60 was computed. |
| Xamarin.iOS | xamarinios xamarinios was computed. |
| Xamarin.Mac | xamarinmac xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos xamarinwatchos was computed. |
Showing the top 1 NuGet packages that depend on Blobject.Disk:
| Package | Downloads |
|---|---|
|
View.Models
Database models, services, and supporting classes for for View AI. |
This package is not used by any popular GitHub repositories.
Fix overwrite truncation, empty writes, filter handling, and shared bulk operations.