read method

Stream<XmlEvent> read()

Implementation

Stream<XmlEvent> read() {
  _controller = new StreamController<XmlEvent>();
  XmlEvent event = createAndAddXmlEvent(XmlState.StartDocument);

  String? prev;
  if (this.stream == null) {
    var chars_raw = this.raw!.split("");
    for (var ch in chars_raw) {
      event = _processRawChar(ch, prev, event);
      prev = ch;
      if (_shutdown) break;
    }
    createAndAddXmlEvent(XmlState.EndDocument);
    _controller.close();
  } else {
    late StreamSubscription controller;
    var onData = (data) {
      var chars_raw = new String.fromCharCodes(data).split("");
      for (var ch in chars_raw) {
        event = _processRawChar(ch, prev, event);
        prev = ch;
        if (_shutdown) {
          controller.cancel();
          break;
        }
      }
    };
    controller = stream!.listen(onData,
        onDone: () {
          createAndAddXmlEvent(XmlState.EndDocument);
          _controller.close();
        });
  }

  return _controller.stream;
}