Skip to content

stakx/PersistentStorage

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 

Repository files navigation

PersistentStorage

A simple, file system-based content addressable storage (CAS).

Basic usage

using PersistentStorage;

// Data will be read from and written to a directory structure contained in
// the directory passed to the constructor:
IPersistentStorage storage = new FileSystemBasedPersistentStorage(@"C:\path\to\some\directory");

// This will create a storage item with a single line of text as its content.
// If the storage already contains an item with the same content, the existing
// item is returned:
IPersistentStorageItem item = await storage.CreateOrGetItemAsync(async (Stream content) =>
{
    using (var contentWriter = new StreamWriter(content))
    {
        contentWriter.WriteLine("Hello world.");
    }
});

// Print the above item's ID (which is the SHA1 hash of its content, formatted
// as a 40-digit hexadecimal number):
Console.WriteLine(item.Id);

// Open some item by its ID, then read and print its content:
var anotherItemId = PersistentStorageItemId.Parse("f479d393efe0776a65b9523319422e0a3dfc9baf");
IPersistentStorageItem anotherItem = await storage.GetItemAsync(anotherItemId);
using (var content = await anotherItem.GetContentAsync())
using (var contentReader = new StreamReader(content))
{
    Console.WriteLine(await contentReader.ReadToEndAsync());
}

Similar prior art

Releases

No releases published

Packages

No packages published

Languages