0

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?

2 Answers2

2

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()

Matthias247
  • 9,836
  • 1
  • 20
  • 29
1

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

Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
Samy Massoud
  • 4,295
  • 2
  • 35
  • 48
  • DICOM is not a just binary data in some file. It is a Digital Imaging and Communications in Medicine (DICOM). Question was "What the best way to parse binary data into strings, ints, and doubles in dart?". – mezoni Mar 03 '14 at 13:13
  • Dear @mezoni this answer for that question , user need to parse binary data to strings,ints and double so i give him entry point , and about DICOM he must go through his way from her ! – Samy Massoud Mar 03 '14 at 13:31
  • And how you advise (in your answer) to parse complex binary structures which may contains as their members the strings, numbers and other structures? How (basically) read data from file we already know from you. What next? Why you not advice to implement custom converter? What if in the some cases binary data format can be so complex that writing converter for it is not possible? What is your advice to start writing this parser? I am sorry, but I not found in your sample code even of the simplest parser. – mezoni Mar 03 '14 at 14:18