public DataStreamContext(Uri u) { string[] parts = u.PathAndQuery.Split(new [] { ',' }, 2); if (parts.Length != 2) { throw SpecFailure.NotValidDataUri(); } var ct = Regex.Replace(parts[0], ";base64", string.Empty); byte[] buffer; _isBase64 = ct.Length < parts[0].Length; // implied by replacement if (_isBase64) { buffer = Convert.FromBase64String(parts[1]); } else { buffer = System.Text.Encoding.ASCII.GetBytes(WebUtility.UrlDecode(parts[1])); } _baseUri = string.Concat("data:", _isBase64 ? ";base64" : string.Empty, "," ); _data = new MemoryStream(buffer.Length); _data.Write(buffer, 0, buffer.Length); }