wdWriteWithBytes method

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

write a file with bytes

Implementation

Future<void> wdWriteWithBytes(
  Client self,
  String path,
  Uint8List data, {
  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);
  }

  // mkdir
  await this._createParent(self, path, cancelToken: cancelToken);

  var resp = await this.req(
    self,
    'PUT',
    path,
    data: Stream.fromIterable(data.map((e) => [e])),
    optionsHandler: (options) =>
        options.headers?['content-length'] = data.length,
    onSendProgress: onProgress,
    cancelToken: cancelToken,
  );
  var status = resp.statusCode;
  if (status == 200 || status == 201 || status == 204) {
    return;
  }
  throw newResponseError(resp);
}