| keywords | IStorage, ManagedCode.Storage.Core, provider-agnostic storage, upload, download, streaming, metadata, Result<T>, .NET |
|---|
Provide a single, provider-agnostic storage API for .NET so application code can upload/download/list/stream files without being coupled to vendor SDKs.
The core package defines:
IStorageand related capability interfaces (IUploader,IDownloader,IStreamer)- consistent
Result/Result<T>error handling - common option models (upload/download/delete/metadata/legal hold)
- provider factories (
IStorageProvider,IStorageFactory) and DI helpers
flowchart LR
App[Application code] --> I[IStorage]
I --> B[BaseStorage<TClient, TOptions>]
B --> C[Provider storage client]
C --> SDK[Vendor SDK / API]
SDK --> B
B --> I
I --> App
- Callers pass
UploadOptions/DownloadOptions/MetadataOptionsto control:FileName,Directory(logical path)MimeType(normalized throughMimeHelper)- per-provider metadata where supported
CopyToAsync and MoveToAsync in ManagedCode.Storage.Core.Extensions take a source
storage and path, a destination storage and path, and an optional cancellation token.
The storages can use different providers. Each successful call returns the destination's
BlobMetadata.
flowchart LR
Source["Read source metadata"] --> Check["Check that destination is vacant"]
Check --> Upload["Upload content and verify length"]
Upload --> Done["Return destination metadata for copy"]
Upload --> Delete["Delete source for move"]
Delete --> DoneMove["Return destination metadata after deletion"]
- If the destination already contains a file at the given path, the operation returns a
409conflict. - Content type and custom metadata travel through the destination provider's upload options. What persists depends on the provider.
- Seekable sources stream directly to the destination. Sequential sources use a temporary local file that the transfer disposes, so providers can determine the length and rewind during upload.
- Coordinate access so other writers and deleters cannot modify either path during the operation. The existence check, upload, and delete are separate provider calls.
- A failed or cancelled write preserves the source. A provider can leave data at the destination if its upload fails after writing. If source deletion fails after a completed upload, the destination stays available. Before retrying a partial move, verify both paths and reconcile the existing destination.
Key files:
ManagedCode.Storage.Core/IStorage.cs— main abstraction surfaceManagedCode.Storage.Core/BaseStorage.cs— shared lifecycle + template methods for providersManagedCode.Storage.Core/Models/*.cs— option models andBlobMetadata/LocalFileManagedCode.Storage.Core/Helpers/Crc32Helper.cs— streamed CRC32 helpers used by chunked uploads/downloadsManagedCode.Storage.Core/Helpers/PathHelper.cs— shared path manipulation utilitiesManagedCode.Storage.Core/Providers/*— provider factory abstractions and the defaultStorageFactoryManagedCode.Storage.Core/Extensions/ServiceCollectionExtensions.cs— DI helpersStorageTransferExtensions— cross-storage file copy and move
- Provider implementations typically inherit
BaseStorage<TClient, TOptions>and only implement provider-specific operations. - Public operations return
Result/Result<T>with:IsSuccessand (when successful)Value- exceptions captured and returned as failed results
- MIME type lookups should flow through
MimeHelper(do not add ad-hoc MIME detection). StringStreamexposes the original UTF-16 code units as little-endian bytes. Byte positions can be odd or past the end of the stream. Attempts to move before the beginning fail and preserve the current position.VerifiedContentSnapshotchecks the declared length and SHA-256 before returning a file-backed snapshot. It reads at most one byte beyond the declared length to detect trailing content.LocalFile.FromStreamAsynccopies from a caller-owned stream and replaces the destination contents. On failure it closes the destination and removes a newly created file. Copies to an existing named destination write in place.- Downloads release their temporary destination when the provider reports failure or returns a file at a different path. A caller-supplied destination stays on disk.
Tests/ManagedCode.Storage.Tests/Core/Crc32HelperTests.csTests/ManagedCode.Storage.Tests/Core/LocalFileTests.csTests/ManagedCode.Storage.Tests/Core/StringStreamTests.csTests/ManagedCode.Storage.Tests/Core/StorageClientChunkTests.cs(core chunk behaviour used by clients)
README.md(package list + quickstart)docs/Testing/strategy.md(suite structure and rules)