readFileStream method

  1. @override
Future<BacnetFileChunk> readFileStream(
  1. int deviceId,
  2. int fileInstance, {
  3. required int start,
  4. required int count,
  5. Duration? timeout,
  6. bool background = false,
  7. BacnetCancelToken? cancelToken,
})
override

Reads up to count octets from position start of File object fileInstance (AtomicReadFile, stream access).

The answer has to fit into one APDU of the device unless it segments answers; readFile (BacnetFileTransfer) reads whole files in fitting chunks.

Implementation

@override
Future<BacnetFileChunk> readFileStream(
  int deviceId,
  int fileInstance, {
  required int start,
  required int count,
  Duration? timeout,
  bool background = false,
  BacnetCancelToken? cancelToken,
}) {
  requests.add(
    FakeBacnetRequest(
      'readFileStream',
      deviceId: deviceId,
      object: _file(fileInstance),
    ),
  );
  return _request(
    BacnetConfirmedService.atomicReadFile,
    deviceId,
    cancelToken,
    (device) {
      final content = device._fileObject(fileInstance)._file!;
      if (start < 0 || start > content.length || count < 0) {
        throw device._error(
          BacnetErrorClass.services,
          BacnetErrorCode.invalidFileStartPosition,
        );
      }
      final end = start + count < content.length
          ? start + count
          : content.length;
      return BacnetFileChunk(
        start: start,
        data: content.sublist(start, end),
        endOfFile: end >= content.length,
      );
    },
  );
}