public static bool Decompile(IDecompileNodeContext context, Stream stream, string name) { if (stream == null || stream.Length > 500 * 1024) { return(false); } stream.Position = 0; FileType type = GuessFileType.DetectFileType(stream); if (type == FileType.Binary) { return(false); } stream.Position = 0; context.Output.Write(FileReader.OpenStream(stream, Encoding.UTF8).ReadToEnd(), TextTokenKind.Text); string ext; if (type == FileType.Xml) { ext = ".xml"; } else { try { ext = Path.GetExtension(NameUtils.CleanName(name)); } catch (ArgumentException) { ext = ".txt"; } } context.HighlightingExtension = ext; return(true); }
public static string TryGetString(Stream stream) { if (stream == null) { return(null); } stream.Position = 0; if (GuessFileType.DetectFileType(stream) == FileType.Binary) { return(null); } stream.Position = 0; return(FileReader.OpenStream(stream, Encoding.UTF8).ReadToEnd()); }