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); }
private void WriteMetaEntry(string contentId, SolidEntryMeta meta) { var bytes = Encoding.UTF8.GetBytes(contentId); _report.MetaLength += Write(bytes.Length); // Write the length of the content id _writer.Write(bytes, 0, bytes.Length); // Write the content ID _report.MetaLength += bytes.Length; _report.MetaLength += Write(meta.ContentOffset); _report.MetaLength += Write(meta.ContentLength); if (meta.Tags != null) { _report.MetaLength += Write(meta.Tags.Count); // Write the length of the tags foreach (var tag in meta.Tags) { _report.MetaLength += Write(tag); // Write the integer value of the tag } } else { _report.MetaLength += Write(0); // No tags provided, record zero len } if (meta.Meta != null) { _report.MetaLength += Write(meta.Meta.Length); // Write the length of the meta file _writer.Write(meta.Meta, 0, meta.Meta.Length); _report.MetaLength += meta.Meta.Length; } else { _report.MetaLength += Write(0); // No per-entry meta provided. Record zero len } }
/// <summary> /// Sets a string identified entry into this solid file - overriding it if it exists /// </summary> /// <param name="id">The id for this entry</param> /// <param name="contents">The raw byte array contents</param> /// <param name="tags">Optional tags to assign to this entry.</param> /// <param name="metaData">Optional metadata to assign to this entry.</param> /// <exception cref="InvalidOperationException">Thrown if the file is flagged immutable or if this entry already exists</exception> public void SetEntry(string id, byte[] contents, IList <string> tags = null, byte[] metaData = null) { if (!Mutable) { throw new InvalidOperationException("File was immutable"); } _pendingContents[id] = contents; var newMeta = new SolidEntryMeta(id, RemapTags(tags), metaData, contents); _entryMetaData[id] = newMeta; }
private void ReadNextEntryMetaData() { int contentIdLen = _reader.ReadInt32(); var contentIdBytes = _reader.ReadBytes(contentIdLen); string contentId = Encoding.UTF8.GetString(contentIdBytes); long contentOffset = _reader.ReadInt64(); int contentLen = _reader.ReadInt32(); int tagCount = _reader.ReadInt32(); int[] tagArr = new int[tagCount]; IList <int> tags = null; if (tagCount > 0) { for (int i = 0; i < tagCount; i++) { int tagInt = _reader.ReadInt32(); tagArr[i] = tagInt; } tags = new List <int>(tagArr); } int metaLen = _reader.ReadInt32(); byte[] meta = null; if (metaLen > 0) { meta = _reader.ReadBytes(metaLen); } var metaEntry = new SolidEntryMeta(contentId, tags, meta, contentLen, contentOffset); _entryMetaData[contentId] = metaEntry; for (int i = 0; i < tagCount; i++) { int tagId = tagArr[i]; List <SolidEntryMeta> existing; if (!_tagLookup.TryGetValue(tagId, out existing)) { existing = new List <SolidEntryMeta>(); _tagLookup[tagId] = existing; } existing.Add(metaEntry); } }