Daniel Oliveira
Daniel Oliveira

Reputation: 8953

How transform a dart's ByteData into a String?

I am reading a binary file and want to transform it into a String. How do I do it in Dart?

Upvotes: 11

Views: 7398

Answers (1)

Oswin Noetzelmann
Oswin Noetzelmann

Reputation: 9545

Try the following

String getStringFromBytes(ByteData data) {
  final buffer = data.buffer;
  var list = buffer.asUint8List(data.offsetInBytes, data.lengthInBytes);
  return utf8.decode(list);
}

Also see this answer.

Upvotes: 6

Related Questions