readFile method

Future<Uint8List> readFile(
  1. int deviceId,
  2. int fileInstance, {
  3. int? chunkSize,
  4. BacnetFileProgress? onProgress,
  5. Duration? timeout,
  6. bool background = false,
  7. BacnetCancelToken? cancelToken,
})

Reads the whole content of File object fileInstance (stream access), in chunks that fit into one APDU of the device.

chunkSize overrides the chunk size; onProgress reports the octets read and File_Size.

final config = await client.readFile(1234, 1,
    onProgress: (done, total) => print('$done / $total'));

Implementation

Future<Uint8List> readFile(
  int deviceId,
  int fileInstance, {
  int? chunkSize,
  BacnetFileProgress? onProgress,
  Duration? timeout,
  bool background = false,
  BacnetCancelToken? cancelToken,
}) async {
  final total = await _fileSize(deviceId, fileInstance, timeout);
  final size = chunkSize ?? await _chunkSize(deviceId);
  final data = BytesBuilder(copy: false);
  onProgress?.call(0, total);
  while (true) {
    final chunk = await readFileStream(
      deviceId,
      fileInstance,
      start: data.length,
      count: size,
      timeout: timeout,
      background: background,
      cancelToken: cancelToken,
    );
    data.add(chunk.data);
    onProgress?.call(data.length, total);
    if (chunk.endOfFile || chunk.data.isEmpty) return data.takeBytes();
  }
}