putCollectionItem static method
Put (create or update) a collection item
Implementation
static Future<CollectionFrameResponse> putCollectionItem(
P2PStream stream, {
required PeerId ownerPeerId,
required String path,
required String key,
required Uint8List content,
String? ifMatch,
}) async {
try {
final headers = <String, String>{};
if (ifMatch != null) {
headers['If-Match'] = ifMatch;
}
final requestBytes = CollectionFrame.encodeRequest(
operation: 'PUT',
ownerPeerId: ownerPeerId,
path: path,
key: key,
headers: headers.isNotEmpty ? headers : null,
body: content,
);
await _writeFrameStatic(stream, requestBytes);
final responseBytes = await _readFrameStatic(stream);
return CollectionFrame.decodeResponse(responseBytes);
} catch (e, stackTrace) {
_logger.severe('Error putting collection item: $e', e, stackTrace);
rethrow;
}
}