Documentation
¶
Overview ¶
Package encsniff detects common non-UTF-8 text encodings from the head of a file or byte slice, using only byte-perfect signatures — no heuristics.
It returns one of three actions: UseAsIs (clean UTF-8/ASCII), StripBom (UTF-8 BOM that should be silently skipped), or Warn (a non-UTF-8 encoding the caller should surface to the user along with an iconv hint).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IconvCommand ¶
IconvCommand composes an iconv command that converts path from enc to UTF-8, writing to a sibling file with .utf8 inserted before the extension. It returns the empty string for encodings that need no conversion.
Types ¶
type Sniff ¶
type Sniff struct {
// Action tells the caller what to do.
Action Action
// Encoding is the detected encoding (empty if UseAsIs and no BOM).
Encoding Encoding
// BomLen is the number of leading bytes to skip when Action == StripBom.
BomLen int
// Hint is a copy-pasteable iconv command. Set by SniffFile when Action ==
// Warn; empty when sniffing bytes with no associated path.
Hint string
}
Sniff is the result of a detection pass.
func SniffBytes ¶
SniffBytes inspects the head of b and returns the detected action. The Hint field is left empty; callers with a path should use SniffFile, or compose a hint with IconvCommand.