I am currently working on a web application to read and write binary DICOM data. My goal is to prove that this is possible and can be done very quickly with Dart.
What the best way to parse binary data into strings, ints, and doubles in dart?
I am currently working on a web application to read and write binary DICOM data. My goal is to prove that this is possible and can be done very quickly with Dart.
What the best way to parse binary data into strings, ints, and doubles in dart?
You should use the dart:typed_data
package to parse values from binary data.
Take a look especially at the ByteData
class which provides a view around your binary data (usually in form of a List<int>
or even better a Uint8List
and allows you to extract values from it:
ByteData API
For parsing Strings from binary data you should use the dart:convert
package: Dart Convert
You might especially be interested in Utf8Codec.decode()
To read file in binary format
import 'dart:io';
main() {
var config = new File('config.txt');
config.readAsBytes().then((List<int> contents) {
print('The entire file is ${contents.length} bytes long');
});
}
put please note Only command-line apps can import and use dart:io.
You might find this helpful
Using file API in dart