UriData.fromBytes constructor

UriData.fromBytes(List<int> bytes, { dynamic mimeType: "application/octet-stream" Map<String, String> parameters, dynamic percentEncoded: false })

Creates a data: URI containing an encoding of bytes.

Equivalent to new Uri.dataFromBytes(...).data, but may be more efficient if the uri itself isn't used.

Implementation

factory UriData.fromBytes(List<int> bytes,
    {mimeType = "application/octet-stream",
    Map<String, String> parameters,
    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);
}