getFormDataHeader method

Map<String, String> getFormDataHeader(
  1. Uint8List data
)

Implementation

Map<String, String> getFormDataHeader(Uint8List data) {
  BytesReader reader = BytesReader.fromUint8List(data);
  String line;
  // group(1) => key, group(4) => value
  RegExp pattern = RegExp(r"([A-z-]*)((:\s)|=)([^;$]*)(;|$)");
  Utf8Decoder decoder = Utf8Decoder();
  Map<String, String> params = {};
  Uint8List r;
  do {
    r = reader.readUntil("\n".codeUnitAt(0));
    // dispose the '\n'
    if (r.isEmpty) {
      break;
    }
    reader.readByte();
    line = decoder.convert(r).trim();
    params.addAll(
      Map.fromEntries(
        pattern.allMatches(line).map<MapEntry<String, String>>(
              (e) => MapEntry(e.group(1).toString(), e.group(4).toString()),
            ),
      ),
    );
  } while (reader.position != reader.data.lengthInBytes);
  return params;
}