writeInPlace static method

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

Write a file in place 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 text/JSON files.

Implementation

static Future<void> writeInPlace({
  required String containerId,
  required String relativePath,
  required String contents,
}) async {
  // Writes are file-centric; reject directory paths.
  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.writeInPlace(
    containerId: containerId,
    relativePath: relativePath,
    contents: contents,
  );
}