public ICompressedItemBuilder Create(CompressedKey key) { // TODO: break down into buckets to avoid files-per-folder limits string physicalPath = Path.Combine(_storagePath, Guid.NewGuid().ToString("n")); return(new ItemBuilder(key, physicalPath)); }
public ICompressedItemHandle Open(CompressedKey key) { lock (_itemsLock) { ItemHandle handle; if (_items.TryGetValue(key, out handle)) { return(handle.Clone()); } return(null); } }
private void AddHandleInDictionary(CompressedKey key, ItemHandle handle) { lock (_itemsLock) { ItemHandle addingHandle = handle.Clone(); ItemHandle existingHandle; if (_items.TryGetValue(key, out existingHandle)) { existingHandle.Dispose(); } _items[key] = addingHandle; } }
public ICompressedItemHandle Commit(ICompressedItemBuilder builder) { var itemBuilder = (ItemBuilder)builder; CompressedKey key = itemBuilder.Key; var item = new Item { PhysicalPath = itemBuilder.PhysicalPath, CompressedLength = itemBuilder.Stream.Length }; itemBuilder.Stream.Close(); var handle = new ItemHandle(item); AddHandleInDictionary(key, handle); return(handle); }
public ItemBuilder(CompressedKey key, string physicalPath) { Key = key; PhysicalPath = physicalPath; Stream = new FileStream(PhysicalPath, FileMode.Create, FileAccess.Write, FileShare.None); }