toZipFile static method

Future<List<int>?> toZipFile(
  1. Map<String, String> ndJsonStrings
)

This function converts a map of ndJson Strings (really any strings, but it was made for ndJson strings), and converts them into the bytes for a .zip file.

Each function takes a Map<String, String> value as an argument. It assumes that each value should be stored in a different file, and the key is the filename with an ndjson extension.

Thus if you pass a map of {patients: patientNdJson, practitioner: practitionerNdJson} The archive will include patients.ndjson and practitioner.ndjson

Lastly, these functions do not return the actual file, so you will have to do a File('fhirData.zip').writeAsBytes(value) in order to store the result somewhere.

Implementation

static Future<List<int>?> toZipFile(Map<String, String> ndJsonStrings) async {
  final Archive archive = Archive();
  ndJsonStrings.forEach((String key, String value) {
    final ArchiveFile file =
        ArchiveFile('$key.ndjson', value.length, utf8.encode(value));
    archive.addFile(file);
  });
  return ZipEncoder().encode(archive);
}