DataBin - uniform data model for raw attachment data stream storage
H.Necessaire provides a uniform data model for raw data stream attachments like documents, images, zip archives, etc.
dotnet add package H.Necessaire
Storing raw data stream, such as email attachments, documents, images, zip archives, etc. is an extremely often scenario in any project. H.Necessaire comes with data models and operations for such scenarios so that it's uniform across modules and projects. And it's called a DataBin.
DataBin Models
DataBin construction help extensions
//Construct the DataBin from DataBinMeta
static DataBin ToBin(this DataBinMeta dataBinMeta, Func<DataBinMeta, Task<ImADataBinStream>> streamFactory)
//Construct ImADataBinStream from Stream
static ImADataBinStream ToDataBinStream(this Stream stream, params IDisposable[] otherDisposables)
View full models on GitHub:
Usage
//Define meta data
DataBinMeta attachmentMeta = new()
{
Name = "attachment.png",
Format = new DataBinFormatInfo
{
ID = "ImagePng",
Extension = "png",
MimeType = "image/png",
Encoding = null,
},
};
//Define data acquisition
H.Necessaire.DataBin attachment
= attachmentMeta
.ToBin(
x => x.Name.OpenEmbeddedResource().ToDataBinStream().AsTask()
);
//Use it
using (ImADataBinStream data = await attachment.OpenDataBinStream())
{
Console.WriteLine(await data.DataStream.ReadAsStringAsync());
}