add method

  1. @override
void add(
  1. List<int> data
)
override

Adds a data event to the sink.

Must not be called on a closed sink.

Implementation

@override
void add(List<int> data) {
  if (_isClosed && isBuffered) {
    throw ResponseContext.closed();
  } else if (!isBuffered) {
    if (!_isClosed) {
      _openStream();

      if (encoders.isNotEmpty && correspondingRequest != null) {
        if (_allowedEncodings != null) {
          for (var encodingName in _allowedEncodings!) {
            Converter<List<int>, List<int>>? encoder;
            var key = encodingName;

            if (encoders.containsKey(encodingName)) {
              encoder = encoders[encodingName];
            } else if (encodingName == '*') {
              encoder = encoders[key = encoders.keys.first];
            }

            if (encoder != null) {
              data = encoders[key]!.convert(data);
              break;
            }
          }
        }
      }

      rawResponse.add(data);
    }
  } else {
    buffer!.add(data);
  }
}