/// <summary> /// Parses a data uri /// </summary> public static BinaryBlob Parse(string dataUri) { var blob = new BinaryBlob(); var reader = new StringReader(dataUri); // data:[<MIME-type>][;charset=<encoding>][;base64],<data> reader.Expect("data:"); blob.ContentType = reader.ReadUntil(ch => ch == ';').Trim(); reader.Read(); reader.Expect("base64,"); blob.Data = Convert.FromBase64String(reader.ReadToEnd()); return blob; }
private static void ParseHeaders(Stream stream, Action<string, string> onHeader) { string headerLine = null; while (true) { headerLine = stream.ReadLine(); if (headerLine == String.Empty) { break; } var headerReader = new StringReader(headerLine); string key = headerReader.ReadUntil(c => c == ':'); headerReader.Read(); headerReader.SkipWhitespace(); string value = headerReader.ReadToEnd(); onHeader(key, value); } }