Esempio n. 1
0
        private void ReadTable()
        {
            _entries.Clear();

            _stream.Seek(-sizeof(uint), SeekOrigin.End);
            _tableOffset = _reader.ReadUInt32();
            _stream.Seek(_tableOffset, SeekOrigin.Begin);
            var count = _reader.ReadUInt32();

            while (count > 0)
            {
                var keyLength = _reader.ReadUInt16();
                var entry     = new ClusterEntry()
                {
                    Key = _reader.ReadBytes(keyLength), Offset = _reader.ReadUInt32(), Length = _reader.ReadUInt32()
                };
                _entries[entry.Key] = entry;

                count--;
            }
        }
Esempio n. 2
0
        public void Set(byte[] key, byte[] value)
        {
            ClusterEntry entry;

            if (_entries.ContainsKey(key))
            {
                entry = _entries[key];
                if (entry.Length <= value.Length)
                {
                    _stream.Seek(entry.Offset, SeekOrigin.Begin);
                    _writer.Write(value);
                    return;
                }
            }

            entry = new ClusterEntry()
            {
                Key = key, Length = (uint)value.Length, Offset = _freeOffset
            };
            _stream.Seek(entry.Offset, SeekOrigin.Begin);
            _writer.Write(value);

            _freeOffset += entry.Length;
        }