byteSize static method

int? byteSize(
  1. Object? value
)

Approximate size of the data in bytes, or null if unknown.

Implementation

static int? byteSize(Object? value) {
  if (value == null) return null;
  try {
    if (value is String) return utf8.encode(value).length;
    if (value is Uint8List) return value.length;
    if (value is List<int>) return value.length;
    if (value is FormData) return value.length;
    return utf8.encode(encode(value)).length;
  } catch (_) {
    return null;
  }
}