getBytes static method

Future<Uint8List?> getBytes(
  1. String key, {
  2. UStorageBucket bucket = UStorageBucket.support,
})

Implementation

static Future<Uint8List?> getBytes(String key, {UStorageBucket bucket = UStorageBucket.support}) async {
  await _ensure();
  final UStorageEntry? entry = _live(key, bucket);
  if (entry == null) return null;
  _touch(entry);
  try {
    if (bucket != UStorageBucket.vault) return await _backend.readAll(_pathFor(bucket, key));
    final BytesBuilder builder = BytesBuilder(copy: false);
    await for (final Uint8List chunk in read(key, bucket: bucket)) {
      builder.add(chunk);
    }
    return builder.takeBytes();
  } on UAuthenticationException {
    debugPrint("UFileStorage: vault entry failed authentication and was removed.");
    await remove(key, bucket: bucket);
    return null;
  }
}