writeInPlaceBytes static method

Future<void> writeInPlaceBytes({
  1. required String containerId,
  2. required String relativePath,
  3. required Uint8List contents,
})

Write a file in place as bytes inside the iCloud container using coordinated access.

relativePath is the path within the iCloud container. contents is the full contents to write.

Trailing slashes are rejected here because writes are file-centric and coordinated through UIDocument/NSDocument.

Coordinated access writes the full contents as a single operation. Use for small files.

Implementation

static Future<void> writeInPlaceBytes({
  required String containerId,
  required String relativePath,
  required Uint8List contents,
}) async {
  if (relativePath.endsWith('/')) {
    throw InvalidArgumentException('invalid relativePath: $relativePath');
  }

  if (relativePath.trim().isEmpty) {
    throw InvalidArgumentException('invalid relativePath: $relativePath');
  }

  if (!_validateRelativePath(relativePath)) {
    throw InvalidArgumentException('invalid relativePath: $relativePath');
  }

  await ICloudStoragePlatform.instance.writeInPlaceBytes(
    containerId: containerId,
    relativePath: relativePath,
    contents: contents,
  );
}