I have a list of 32-bit unsigned integers:
var unixTimestamps = [
1573613134,
1573623934,
1573631134,
1573659934,
1573746334,
1573731934,
1573764334,
1573789534,
1573847134,
1573933534,
1573893934,
1573980334,
1574153134,
1574178334
];
I would like to save these to a file.
The list needs to be written iteratively as it depends on the user's interaction with the app.
final file = await _localFile(filename);
for (var i=0; i<unixTimestamps.length; i++){
file.writeAsBytesSync(unixTimestamps[i], mode: FileMode.append)
}
with
Future _localFile(String filename) async {
final path = await _localPath();
return File('$path/$filename');
}
Future _localPath() async {
final directory = await getApplicationDocumentsDirectory();
return directory.path;
}
When I read back the data from that file, I noticed that it's unsigned 8-bit integers. (Values are between 0 and 255)
Below is the readData script:
Future readData(filename, i) async {
try {
final file = await _localFile(filename);
List contents = await file.readAsBytesSync();
return contents;
} catch (e) {
print(e);
return 0;
}
}
Is there a way for files to be saved and read as 32 bit integers?