read method

  1. @override
Future<List<int>?> read(
  1. String key
)
override

Returns the object's bytes, or null if it does not exist.

Implementation

@override
Future<List<int>?> read(String key) async {
  final result = await Process.run(aws, [
    's3',
    'cp',
    _url(key),
    '-',
    '--only-show-errors',
  ], stdoutEncoding: null);
  if (result.exitCode == 0) return result.stdout as List<int>;
  final error = '${result.stderr}';
  if (error.contains('404') ||
      error.contains('Not Found') ||
      error.contains('NoSuchKey') ||
      error.contains('does not exist')) {
    return null;
  }
  throw CliException('aws s3 cp ${_url(key)} failed: ${error.trim()}');
}