question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add an overload to ParseDocument(Stream stream, Encoding encoding) to specify an encoding

See original GitHub issue

Is there a way to load a HtmlDocument from a byte array / a stream specifying which character encoding to use? We currently are loading the HTML document this way:

Encoding encoding = ...
using (MemoryStream ms = new MemoryStream(bytes))
{
	this.document = parser.ParseDocument(ms); // I cannot specify the given encoding
}

If I understood correctly, AngleSharp tries to detect the proper encoding, but encoding could be specified in various ways (HTTP headers, Byte Order Mark, meta content-type and meta charset), so at least the HTTP header case cannot be known by the parser.

We are trying to move away from HtmlAgilityPack, which in its equivalent class has an overload to specify the encoding to use. In our program byte array can be read from the web, or be loaded from a local DB. In most cases we already have the encoding, plus we wish to permit users to visualize HTML content with a different encoding.

Does AngleSharp already provide a way to do it?

If not, can I request an implementation? Can you add an overload: HtmlParser.ParseDocument(Stream stream, Encoding encoding) to specify an encoding

If the current method tries to detect the encoding, it would mean also a performance improvement when the encoding is already know.

Thank you

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
fedesassocommented, Mar 4, 2022

Hey, that was a prompt and detailed answer! A lot to study for me… thank you!

0reactions
FlorianRapplcommented, May 31, 2022

Landed in devel.

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - Forcing StreamWriter to change Encoding
Just wrap it in a FileStream . StreamWriter sw = new StreamWriter( new FileStream(saveFileDialog1.FileName, FileMode.Open, FileAccess.
Read more >
How to fix encoder overloaded | OBS - YouTube
Twitch Encoder Presets: https:// stream.twitch.tv/ encoding / My Other YouTube Channels: ▻CalmCoolSavage ( Tutorials ) ...
Read more >
Correctly reading encoded text with the StreamReader in .NET
I can use an overload where I specify the encoding type, which comes from System.Text.Encoding. var streamReader = new StreamReader( ...
Read more >
Fix OBS Encoding Overloading | Easy OBS Studio Guide
If you're trying to record or stream a demanding game in OBS Studio, you've likely come across this issue. This video shows you...
Read more >
How to Fix OBS Encoding Overloaded Error (100% Work)
Launch OBS and go to 'Settings'. Select 'Output'. From the 'Streaming' block, change the encoder preset from 'veryfast' to 'superfast' or ' ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found