CharsetDetector / UTF-unknown

Character set detector build in C# - .NET 5+, .NET Core 2+, .NET standard 1+ & .NET 4+
303 stars 45 forks source link

Remove static methods from CharsetDetector, add an interface and create CharsetDetector.Instance #134

Open 304NotModified opened 2 years ago

304NotModified commented 2 years ago

For mocking.

e.g.

interface ICharsetDetector
{
  DetectionResult DetectFromBytes(byte[] bytes);
  DetectionResult DetectFromBytes(byte[] bytes, int offset, int len); 
  DetectionResult DetectFromStream(Stream stream);
  DetectionResult DetectFromStream(Stream stream, long? maxBytesToRead);
}

public class CharsetDetector 
{
   public ICharsetDetector Instance => _instance;
}

and move to extensions for SRP:

public static class CharsetDetectorFileExtensions
{
public static DetectionResult DetectFromFile(this ICharsetDetector detector, string filePath) {...}
public static DetectionResult DetectionResult DetectFromFile(this ICharsetDetector detector, FileInfo file) {...}