fromCompressedData static method
Accepts data that is zipped, x-zip-compressed, tar, or gz. Note, this function assumes that all uncompressed data is in ndjson format
Implementation
static Future<List<Resource>> fromCompressedData(
String contentType, dynamic content) async {
final List<Resource> resourceList = <Resource>[];
if (contentType == 'application/zip' ||
contentType == 'application/x-zip-compressed') {
final Archive archive = ZipDecoder().decodeBytes(content as List<int>);
for (final ArchiveFile file in archive) {
if (file.isFile) {
final List<int> data = file.content as List<int>;
resourceList.addAll(fromNdJson(utf8.decode(data)));
}
}
} else if (contentType == 'application/x-tar') {
final List<int> unzipped =
GZipDecoder().decodeBytes(content as List<int>);
final Archive archive = TarDecoder().decodeBytes(unzipped);
for (final ArchiveFile file in archive) {
if (file.isFile) {
resourceList
.addAll(fromNdJson(utf8.decode(file.content as List<int>)));
}
}
} else if (contentType == 'application/gzip') {
final List<int> data = GZipDecoder().decodeBytes(content as List<int>);
resourceList.addAll(fromNdJson(utf8.decode(data)));
}
return resourceList;
}