toTarGzFile static method

Future<List<int>?> toTarGzFile(
  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 .tar.gz 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 the appropriate extensions).

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.tar.gz').writeAsBytes(value) in order to store the result somewhere.

Implementation

static Future<List<int>?> toTarGzFile(
    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);
  });
  final List<int> tarredArchive = TarEncoder().encode(archive);
  return GZipEncoder().encode(tarredArchive);
}