public Task <Stream> Read(Uri path) { var pathInfo = new PathInfo(path); this.AssertIsValidWabsUri(pathInfo); StorageSimulatorItem item = this.GetItem(pathInfo); if (item.IsNull()) { throw new InvalidOperationException("Attempt to read an item that was not present in the container."); } Stream stream = Help.SafeCreate <MemoryStream>(); stream.Write(item.Data, 0, item.Data.Length); stream.Position = 0; return(Task.FromResult(stream)); }
protected StorageSimulatorItem GetItem(PathInfo pathInfo, bool parent = false) { StorageSimulatorItem dir = this.Root; this.Root.Items.TryGetValue(pathInfo.Container, out dir); string[] pathParts = pathInfo.PathParts; if (parent) { if (pathParts.Length > 0) { pathParts = pathParts.Take(pathParts.Length - 1).ToArray(); } } if (pathParts.Length == 0) { return(dir); } int loc = 0; while (dir.IsNotNull() && dir.Items.TryGetValue(pathParts[loc], out dir) && loc < pathParts.Length) { if (loc == pathParts.Length - 1) { return(dir); } if (dir.IsNull()) { return(null); } loc++; } return(null); }