readFromStream static method

Future<Tag> readFromStream(
  1. Uint8List list, [
  2. void onReadListener(
    1. int
    )?
])

Implementation

static Future<Tag> readFromStream(Uint8List list,
    [void Function(int)? onReadListener]) async {
  _io.disposeStream();
  _io = ByteLayer();
  _io.addListener(onReadListener);

  try {
    _io.writeBytes(list);
    _io.resetPosition();
  } catch (E) {
    print(E);
  } finally {
    if (_io.readByte() == TagType.Compound.byte) {
      _io.resetPosition();
      return Tag.readNamedTag(_io, depth: 0);
    } else {
      _io.resetPosition();
      _io.decompress();
      _io.resetPosition();
      return Tag.readNamedTag(_io, depth: 0);
    }
  }
}