createHandle method
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 kind = entityKindOf(entity);
final fixedKind = fixedEntityKind;
if (fixedKind != null && fixedKind != kind) {
throw ArgumentError.value(
entity,
'entity',
'This backend accepts only ${fixedKind.name} entities.',
);
}
final bookmark = await createBookmark(
entity,
access: MacOSSecurityScopedBookmarkAccess.readWrite,
);
final encodedBookmark = bookmark.encode();
if (fixedKind != null) {
return encodedBookmark;
}
final payload = jsonEncode({
'kind': kind.name,
'bookmark': encodedBookmark,
'path': path.normalize(entity.absolute.path),
});
return '$_mixedHandlePrefix${base64Url.encode(utf8.encode(payload))}';
}