wdReadWithBytes method

Future<List<int>> wdReadWithBytes(
  1. Client self,
  2. String path, {
  3. void onProgress(
    1. int count,
    2. int total
    )?,
  4. CancelToken? cancelToken,
})

read a file with bytes

Implementation

Future<List<int>> wdReadWithBytes(
  Client self,
  String path, {
  void Function(int count, int total)? onProgress,
  CancelToken? cancelToken,
}) async {
  // fix auth error
  var pResp = await this.wdOptions(self, path, cancelToken: cancelToken);
  if (pResp.statusCode != 200) {
    throw newResponseError(pResp);
  }

  var resp = await this.req(
    self,
    'GET',
    path,
    optionsHandler: (options) => options.responseType = ResponseType.bytes,
    onReceiveProgress: onProgress,
    cancelToken: cancelToken,
  );
  if (resp.statusCode != 200) {
    if (resp.statusCode != null) {
      if (resp.statusCode! >= 300 && resp.statusCode! < 400) {
        return (await this.req(
          self,
          'GET',
          resp.headers["location"]!.first,
          optionsHandler: (options) =>
              options.responseType = ResponseType.bytes,
          onReceiveProgress: onProgress,
          cancelToken: cancelToken,
        ))
            .data;
      }
    }
    throw newResponseError(resp);
  }
  return resp.data;
}