createFile method

  1. @override
void createFile(
  1. String path, {
  2. bool errorIfNotExists = false,
  3. bool errorIfAlreadyExists = false,
})
override

Creates an empty file at path.

If errorIfAlreadyExists is set to true, and a file already exists at path, a FileSystemException is thrown.

Implementation

@override
void createFile(String path,
    {bool errorIfNotExists = false, bool errorIfAlreadyExists = false}) {
  final type = _recognizeType(path);
  if (type == null) {
    throw ArgumentError.value(
      path,
      'path',
      'Invalid path for OPFS file system, only ${FileType._validNames} are '
          'supported!',
    );
  } else {
    _metaHandle.read(_existsList, FileSystemReadWriteOptions(at: 0));
    final exists = _existsList[type.index] != 0;

    if ((exists && errorIfAlreadyExists) || (!exists && errorIfNotExists)) {
      throw FileSystemException();
    }

    if (!exists) {
      _markExists(type, true);
      _files[type]!.truncate(0);
    }
  }
}