WIP, abandoned: One-way backup tool with versioning and client-side encryption. Your precious data will never get lost!
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.5 KiB

namespace EternalArrowBackup.TargetBinaryStorage.InMemoryBinaryStorage
{
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using EternalArrowBackup.TargetBinaryStorage.Contracts;
public class BinaryStorage : ITargetBinaryStorage
{
private Dictionary<string, IBlobInfo> Blobs { get; } = new Dictionary<string, IBlobInfo>();
private Dictionary<BlockId, BlockInfo> Blocks { get; } = new Dictionary<BlockId, BlockInfo>();
public Task<IBlobInfo> GetBlobIfExists(string blobId)
{
if (!this.Blobs.ContainsKey(blobId))
{
return Task.FromResult(default(IBlobInfo));
}
return Task.FromResult(this.Blobs[blobId]);
}
public Task WriteBlob(string blobId, long originalSize, string[] blockKeys)
{
return Task.Run(() =>
{
this.Blobs[blobId] = new BlobInfo(DateTime.UtcNow, originalSize, blockKeys);
});
}
public Task WriteBlock(byte[] block, string blobId, int partNumber, string blockKey)
{
return Task.Run(() =>
{
this.Blocks[new BlockId(blobId, blockKey)] = new BlockInfo(blobId, partNumber, blockKey, block);
});
}
public Task<byte[]> RetrieveBlock(string blobId, string blockKey)
{
return Task.Run(() => this.Blocks[new BlockId(blobId, blockKey)].BlockData);
}
}
}