parse static method

BlobStore parse(
  1. String spec, {
  2. required String aws,
  3. required Directory projectDir,
})

Parses s3://bucket/prefix, file:///dir, or a folder path.

Implementation

static BlobStore parse(
  String spec, {
  required String aws,
  required Directory projectDir,
}) {
  if (spec.startsWith('s3://')) {
    final rest = spec.substring(5);
    final slash = rest.indexOf('/');
    final bucket = slash < 0 ? rest : rest.substring(0, slash);
    var prefix = slash < 0 ? '' : rest.substring(slash + 1);
    while (prefix.endsWith('/')) {
      prefix = prefix.substring(0, prefix.length - 1);
    }
    if (bucket.isEmpty) throw CliException('Bad store "$spec": no bucket.');
    return S3Store(bucket: bucket, prefix: prefix, aws: aws);
  }
  if (spec.startsWith('file://')) {
    return FileStore(Directory(Uri.parse(spec).toFilePath()));
  }
  return FileStore(Directory(resolvePath(spec, projectDir)));
}