charset_codec library
Cross-platform character encoding codecs aligned with CPython behavior.
Provides encoding and decoding, strict validation, asynchronous processing, and bounded incremental processing across Dart VM, Flutter, and Web.
Classes
- CharsetCodec
-
Encodes, decodes, and creates incremental processors for one charset.
Obtain instances through the top-level
codecfunction and reuse them across calls. Codec tables are loaded on demand. - CodecInfo
- Describes a codec resolved by this package.
- IncrementalDecoder
- Decodes a byte stream while retaining only bounded codec state.
- IncrementalEncoder
- Encodes a text stream while retaining only bounded codec state.
Enums
- CodecErrorMode
- Selects how malformed input or unrepresentable text is handled.
- CodecOperation
- The conversion direction associated with a CodecException.
Properties
-
supportedPythonCodecNames
→ Iterable<
String> -
All normalized CPython codec names supported by this package.
no setter
Functions
-
codec(
String encoding) → CharsetCodec -
Resolves
encodingto a codec using its canonical name or a common alias. -
decodeBytes(
List< int> bytes, {required String encoding, CodecErrorMode errors = CodecErrorMode.strict}) → String -
Decodes
byteswithencoding. -
decodeBytesAsync(
List< int> bytes, {required String encoding, CodecErrorMode errors = CodecErrorMode.strict}) → Future<String> -
Asynchronously decodes
byteswithencoding. -
encodeString(
String text, {required String encoding, CodecErrorMode errors = CodecErrorMode.strict}) → Uint8List -
Encodes
textwithencodingand returns a new byte buffer. -
encodeStringAsync(
String text, {required String encoding, CodecErrorMode errors = CodecErrorMode.strict}) → Future< Uint8List> -
Asynchronously encodes
textwithencoding. -
isValidDataForEncoding(
List< int> data, String encoding) → bool -
Whether
datais completely valid forencodingin strict mode. -
isValidDataForEncodingAsync(
List< int> data, String encoding) → Future<bool> -
Asynchronously checks whether
datais strictly valid forencoding. -
lookupCodecInfo(
String encoding) → CodecInfo? -
Looks up metadata for
encoding, accepting canonical names and aliases. -
tryDecodeBytes(
List< int> bytes, {required String encoding, CodecErrorMode errors = CodecErrorMode.strict}) → String? -
Tries to decode
byteswithencoding, returningnullon any failure. -
tryEncodeString(
String text, {required String encoding, CodecErrorMode errors = CodecErrorMode.strict}) → Uint8List? -
Tries to encode
textwithencoding, returningnullon any failure.
Exceptions / Errors
- CodecException
- A structured codec lookup or conversion failure. Contains the encoding name, operation, error position, and readable reason for display or logging by callers.