createCollection static method

Future<CollectionFrameResponse> createCollection(
  1. P2PStream stream, {
  2. required PeerId ownerPeerId,
  3. required String path,
  4. required String name,
  5. CollectionVisibility? visibility,
})

Create a new collection.

Without a visibility the server makes the collection private.

Implementation

static Future<CollectionFrameResponse> createCollection(
  P2PStream stream, {
  required PeerId ownerPeerId,
  required String path,
  required String name,
  CollectionVisibility? visibility,
}) async {
  try {
    final requestBytes = CollectionFrame.encodeRequest(
      operation: 'CREATE',
      ownerPeerId: ownerPeerId,
      path: path,
      name: name,
      visibility: visibility?.name,
    );

    await _writeFrameStatic(stream, requestBytes);
    final responseBytes = await _readFrameStatic(stream);
    return CollectionFrame.decodeResponse(responseBytes);
  } catch (e, stackTrace) {
    _logger.severe('Error creating collection: $e', e, stackTrace);
    rethrow;
  }
}