zip method
Implementation
Uint8List zip(Map<String,dynamic> data, [Map<String,dynamic>? opts]) {
opts ??= {};
final Map<String,dynamic> r = {};
List files = [];
fltn(data, '', r, opts);
int o = 0;
int tot = 0;
for (final fn in r.keys) {
var _a = r[fn], file = _a[0];
Map<String,dynamic> p = _a[1];
int compression = (p['level'] ?? 0) == 0 ? 0 : 8;
u8 f = strToU8(fn);
int s = f.length;
var com = p['comment'] ?? 0;
var m = (com != 0 && strToU8(com) != 0) ? strToU8(com) : com;//com && strToU8(com);
int ms = (m != 0 && m.length != 0) ? m.length : m;//m && m.length;
int exl = exfl(p['extra']);
if (s > 65535){
err(11);
}
var d = compression != 0? deflateSync(file, p) : file;
int l = d.length;
Map<String,Function> c = crc();
c['p']?.call(file);
files.add(mrg(p, {
'size': file.length,
'crc': c['d']?.call(),
'c': d,
'f': f,
'm': m,
'u': s != fn.length || (m != 0 && (com.length != ms)),
'o': o,
'compression': compression
}));
o += 30 + s + exl + l;
tot += 76 + 2 * (s + exl) + ms + l;
}
Uint8List out = u8(tot + 22);
int oe = o, cdl = tot - o;
for (int i = 0; i < files.length; ++i) {
Map f = files[i];
wzh(out, f['o'], f, f['f'], f['u'], f['c'].length);
int badd = 30 + (f['f'].length as int) + exfl(f['extra']);
out.setAll(f['o'] + badd,f['c']);//out[f['c']] = f['o'] + badd;
wzh(out, o, f, f['f'], f['u'], f['c'].length, f['o'],
f['m']);
o += 16 + badd + (f['m'] is int? (f['m'] as int):(f['m'].length) as int);//(f['m'] != null? f['m'].length : 0) as int;
}
wzf(out, o, files.length, cdl, oe);
return out;
}