UriData.fromBytes 构造函数

UriData.fromBytes(
  1. List<int> bytes,
  2. {String mimeType = "application/octet-stream",
  3. Map<String, String>? parameters,
  4. bool percentEncoded = false}
)

创建一个包含 bytes 编码的 data: URI。

相当于 Uri.dataFromBytes(...).data,但可能更高效,如果不需要使用 uri

实现

factory UriData.fromBytes(List<int> bytes,
    {String mimeType = "application/octet-stream",
    Map<String, String>? parameters,
    bool percentEncoded = false}) {
  StringBuffer buffer = StringBuffer();
  List<int> indices = [_noScheme];
  _writeUri(mimeType, null, parameters, buffer, indices);
  indices.add(buffer.length);
  if (percentEncoded) {
    buffer.write(',');
    _uriEncodeBytes(_uricTable, bytes, buffer);
  } else {
    buffer.write(';base64,');
    indices.add(buffer.length - 1);
    _base64.encoder
        .startChunkedConversion(StringConversionSink.fromStringSink(buffer))
        .addSlice(bytes, 0, bytes.length, true);
  }

  return UriData._(buffer.toString(), indices, null);
}