예제 #1
0
        public SolidEntry GetFromMeta(SolidEntryMeta meta)
        {
            SolidEntry entry = new SolidEntry();

            entry.Id = meta.Id;

            if (Mutable) // Support the use case when we're requesting a read on an archive thats being build
            {
                entry.Contents = _pendingContents[entry.Id];
            }
            else
            {
                _reader.BaseStream.Position = meta.ContentOffset + _indexOffset; // Scrub the reader to the position
                entry.Contents = _reader.ReadBytes(meta.ContentLength);
            }


            if (meta.Tags != null)
            {
                int      tagCnt = meta.Tags.Count;
                string[] tags   = new string[tagCnt];
                for (int i = 0; i < tagCnt; i++)
                {
                    tags[i] = _tagIndexToTag[meta.Tags[i]];
                }
                entry.Tags = new List <string>(tags);
            }

            entry.ContentOffset = meta.ContentOffset;
            entry.ContentLength = meta.ContentLength;
            entry.MetaData      = meta.Meta;

            return(entry);
        }
예제 #2
0
        /// <summary>
        /// Adds the provided solid entry in this archive.
        /// </summary>
        /// <param name="entry">The details associated with this entry</param>
        /// <exception cref="InvalidOperationException">Thrown if the archive is flagged immutable or if this entry already exists</exception>
        public void AddEntry(SolidEntry entry)
        {
            if (!Mutable)
            {
                throw new InvalidOperationException("File was immutable");
            }

            if (_entryMetaData.ContainsKey(entry.Id))
            {
                throw new InvalidOperationException("Entry " + entry.Id + " already exists");
            }
            SetEntry(entry.Id, entry.Contents, entry.Tags, entry.MetaData);
        }