/// <summary> /// Converts a stream by copying it to a memory stream and returning /// as a string with encoding. /// </summary> /// <param name="s">stream to turn into a string</param> /// <param name="encoding">Encoding of the stream. Defaults to Unicode</param> /// <returns>string </returns> public static string AsString(this Stream s, Encoding encoding = null) { using (var ms = new MemoryStream()) { s.CopyTo(ms); s.Position = 0; return(ms.AsString(encoding)); } }
public void CanEncodeToStream() { var bstring = new BString("hello world"); using (var stream = new MemoryStream()) { bstring.EncodeTo(stream); stream.Length.Should().Be(14); stream.AsString().Should().Be("11:hello world"); } }
public void GetFirstWebSurgeValue() { RegistryKey registryKey = Registry.CurrentUser.OpenSubKey( @"Software\Microsoft\Windows\CurrentVersion\Explorer\RecentDocs\.websurge"); byte[] bytes = registryKey.GetValue("1") as byte[]; var ms = new MemoryStream(bytes); string value = ms.AsString(); Console.WriteLine(value); value = StringUtils.ExtractString(value, "", "\0"); Console.WriteLine(value); }
public static string CreateFromFile(this string fake, string fileName) { var stream = new MemoryStream(); stream.LoadFromFile(fileName); return stream.AsString(); }