public System.IO.Stream GetContent(RootName root, FileId source)
        {
            if (!_contentCache.ContainsKey(source))
            {
                var data    = _localState.GetContent(root, source);
                var evt     = NetworkContentLocator.FromBytes(data.ReadFully());
                var content = evt.MapOrContent;
                if (evt.IsMap)
                {
                    content = _imdStore.GetImDAsync(evt.MapOrContent).GetAwaiter().GetResult();
                }

                _contentCache[source] = content;
            }

            // If you create a MemoryStream over a pre-allocated byte array,
            // it can't expand (ie. get longer than the size you specified when you started).
            // The key is to use the empty (no params) MemoryStream() ctor, which creates it as expandable.
            var ms    = new System.IO.MemoryStream();
            var bytes = _contentCache[source];

            ms.Write(bytes, 0, bytes.Length);
            ms.Seek(0, System.IO.SeekOrigin.Begin);
            return(new System.IO.BufferedStream(ms));
        }
Example #2
0
 public Task <byte[]> LoadContent(byte[] map)
 => _imdStore.GetImDAsync(map);