/// <summary>
        /// Открывет на чтение файловый поток
        /// </summary>
        /// <param name="name"></param>
        /// <param name="versionHash"></param>
        /// <returns></returns>
        public Stream Open(string name, string versionHash = null)
        {
            string datahash = null;
            string namehash = null;

            using (var o = _mapper.Open(name)) {
                if (string.IsNullOrWhiteSpace(versionHash))
                {
                    versionHash = o.GetHeadHash();
                    if (versionHash == Const.DETACHEDHEAD)
                    {
                        throw new Exception("head is detached");
                    }
                }
                var c = o.Resolve(versionHash);
                if (null == c)
                {
                    throw new Exception("commit " + versionHash + " not resolved");
                }
                datahash = c.Hash;
                namehash = o.MappingInfo.NameHash;
            }
            var binrecord = new HashedDirectoryRecord {
                DataHash = datahash, NameHash = namehash
            };

            return(_hashed.Open(binrecord));
        }
        public void CanWriteAndRead(string file, string content, bool compressed)
        {
            hashdir = new HashedDirectory(dir + "/compress_" + compressed, compressed, 7);
            for (var i = 0; i <= 10; i++)
            {
                content = content + content;
            }
            var record = hashdir.Write(file, content);

            WriteDirToConsole();
            Assert.NotNull(record);
            Assert.AreNotEqual(record.NameHash, record.DataHash);
            Assert.AreEqual(7, record.NameHash.Length);
            Assert.AreEqual(7, record.DataHash.Length);
            Assert.AreEqual(DateTime.Now.Year, record.LastWriteTime.Year);

            var res = new StreamReader(hashdir.Open(record)).ReadToEnd();

            Assert.AreEqual(content, res);
            res = new StreamReader(hashdir.Open(file)).ReadToEnd();
            Assert.AreEqual(content, res);
        }
Beispiel #3
0
 /// <summary>
 ///     Получение потока до файла
 /// </summary>
 /// <param name="access">Уровень доступа до потока</param>
 /// <returns>Поток до файла</returns>
 public Stream GetStream(FileAccess access)
 {
     return(_hashedDirectoryStorage.Open(Descriptor.Path));
 }