createHandle method

  1. @override
Future<String> createHandle(
  1. FileSystemEntity entity
)
override

Creates an opaque persistent handle for an authorized entity.

The returned handle must be non-empty, and handles for distinct identities or entity kinds must be distinct. It must be structurally accepted by describeHandle and withHandleAccess, although resolution or access may still fail temporarily. Whenever resolution succeeds, it must produce the same entityIdentity and entity kind as entity, and its kind must agree with describeHandle when the description includes one. When the description has an identity, it must also match entity. Collections verify these requirements before persisting a successfully resolved handle; a temporarily failing handle is retained for a later retry.

Implementation

@override
Future<String> createHandle(final FileSystemEntity entity) async {
  final requestedKind = entityKindOf(entity);
  final normalizedPath = path.normalize(entity.absolute.path);
  final actualKind = await _kindAtPath(normalizedPath);
  if (actualKind != requestedKind) {
    throw ArgumentError.value(
      entity,
      'entity',
      'The filesystem entity kind does not match the path.',
    );
  }
  final payload = jsonEncode({
    'kind': requestedKind.name,
    'path': normalizedPath,
  });
  return '$_versionedHandlePrefix${base64Url.encode(utf8.encode(payload))}';
}