getString method
Reads a region of the buffer as an encoded string
.
Items are read from the range [offset : offset+length]
. If length
is omitted, the range
extends to the end of the buffer.
The range must satisy the relations 0
≤ offset
≤ offset+length
≤ this.length
.
final Buffer buffer = Buffer.fromList([72, 105, 32, 75, 97, 116, 101]);
final String hex = buffer.getString(BufferEncoding.hex);
print(hex); // '4869204B617465'
Implementation
String getString(final BufferEncoding encoding, [final int offset = 0, final int? length]) {
final int end = length != null ? offset + length : this.length;
final Iterable<int> bytes = _data.getRange(offset, end);
return _encode(Uint8List.fromList(bytes.toList(growable: false)), encoding);
}