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)); }
object Apply(NetworkFileItemCreated e) { var locator = new NetworkContentLocator { ContentId = e.SequenceNr, IsMap = e.IsMap, MapOrContent = e.MapOrContent }; var stream = new MemoryStream(locator.GetBytes()); return(_localState.NewFileItem(_root, new DirectoryId(e.ParentDirId), e.Name, stream, null)); }
object Apply(NetworkFileContentSet e) { var locator = new NetworkContentLocator { ContentId = e.SequenceNr, IsMap = e.IsMap, MapOrContent = e.MapOrContent }; var stream = new MemoryStream(locator.GetBytes()); _localState.SetContent(_root, new FileId(e.FileId), stream, null); return(new object()); }