clear static method

Future<void> clear({
  1. UStorageBucket? bucket,
  2. bool includeDownloads = false,
})

Clears one bucket, or every bucket when bucket is null. Partial downloads survive unless includeDownloads is true.

Implementation

static Future<void> clear({UStorageBucket? bucket, bool includeDownloads = false}) async {
  await _ensure();
  for (final _BucketIndex index in _indexes.values) {
    if ((bucket != null && index.bucket != bucket) || !index.available) continue;
    for (final UStorageEntry entry in index.entries.values.toList()) {
      await _backend.delete(uJoinPath(index.root, entry.file));
    }
    index.entries.clear();
    if (includeDownloads) await _backend.deleteDirectory(uJoinPath(index.root, "parts"));
    await _saveIndex(index);
    _events.add(UStorageEvent(UStorageEventType.cleared, index.bucket));
  }
}