Пример #1
0
        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));
        }
Пример #2
0
 public ICompressedItemHandle Open(CompressedKey key)
 {
     lock (_itemsLock)
     {
         ItemHandle handle;
         if (_items.TryGetValue(key, out handle))
         {
             return(handle.Clone());
         }
         return(null);
     }
 }
Пример #3
0
 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;
     }
 }
Пример #4
0
        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);
        }
Пример #5
0
 public ItemBuilder(CompressedKey key, string physicalPath)
 {
     Key          = key;
     PhysicalPath = physicalPath;
     Stream       = new FileStream(PhysicalPath, FileMode.Create, FileAccess.Write, FileShare.None);
 }