It's pretty easy to load an asset after waiting for Future<Map<String, T>>
. It's even easier to embed the file within the program code.
import 'dart:convert' as JSON;
void main() {
var jsonStr = """{ "en": "Greetings, World!", "cn": "你好,世界!" }""";
final json = JSON.jsonDecode(jsonStr);
print(json.length);
}
But suppose I compress and uuencode file.json.gz file.json.gz
the JSON string above, obtaining:
begin 644 file.json.gz
M'XL("#1&\F```V9I;&4N:G-O;@"K5E!*S5.R4E!R+TI-+<G,2R_640C/+\I)
G453245!*!DL]V;O@Z=*][_?T/-DQ[?G4'D4EA5HN`+"N/9PX````
`
end
and then embed the result within the code:
import 'dart:convert' as JSON;
void main() {
var str = """ M'XL("#1&\F```V9I;&4N:G-O;@"K5E!*S5.R4E!R+TI-+<G,2R_640C/+\I)
G453245!*!DL]V;O@Z=*][_?T/-DQ[?G4'D4EA5HN`+"N/9PX````
`""";
...
}
How might I uudecode the uuencoded string in Dart?
Modernizing to base64
As jamesdlin's nicely detailed answer suggests (and notwithstanding that the answer handles uuencode
), the use of base64 is superior, and it can be obtained still from uuencode
using the -m
switch.
> uuencode -m file.json.gz file.json.gz
begin-base64 644 file.json.gz
H4sICH6y8mAAA2ZpbGUuanNvbgCrVlBKzVOyUlByL0pNLcnMSy/WUQjPL8pJUVTSUVBKBks92bvg
6dK97/f0PNkx7fnUHkUlhVouALCuPZw4AAAA
====
In that case we can use base64Decode
from dart:convert
.
void main() {
var str = """begin-base64 644 file.json.gz
H4sICH6y8mAAA2ZpbGUuanNvbgCrVlBKzVOyUlByL0pNLcnMSy/WUQjPL8pJUVTSUVBKBks92bvg
6dK97/f0PNkx7fnUHkUlhVouALCuPZw4AAAA
====""";
...
}