createOrOpen static method

ZvecCollection createOrOpen({
  1. required String path,
  2. required int dimension,
  3. String name = 'default',
})

Implementation

static ZvecCollection createOrOpen({
  required String path,
  required int dimension,
  String name = 'default',
}) {
  final collectionDirectory = Directory(path);
  if (collectionDirectory.existsSync()) {
    final collection = open(path);
    final currentDimension = collection.dimension;
    if (currentDimension != dimension) {
      collection.close();
      throw ZvecException(
        -1,
        'Existing collection dimension is $currentDimension, expected $dimension.',
      );
    }
    return collection;
  }

  collectionDirectory.parent.createSync(recursive: true);
  return create(path: path, dimension: dimension, name: name);
}