deleteDocument static method

Future<DocumentFrameResponse> deleteDocument(
  1. P2PStream stream, {
  2. required PeerId ownerPeerId,
  3. required String path,
  4. String? ifMatch,
})

Delete a document (client-side)

Implementation

static Future<DocumentFrameResponse> deleteDocument(
  P2PStream stream, {
  required PeerId ownerPeerId,
  required String path,
  String? ifMatch,
}) async {
  try {
    final headers = <String, String>{};
    if (ifMatch != null) {
      headers['If-Match'] = ifMatch;
    }

    final requestBytes = DocumentFrame.encodeRequest(
      operation: 'DELETE',
      ownerPeerId: ownerPeerId,
      path: path,
      headers: headers,
    );

    await _writeFrameStatic(stream, requestBytes);

    // Read response
    final responseBytes = await _readFrameStatic(stream);
    return DocumentFrame.decodeResponse(responseBytes);
  } catch (e, stackTrace) {
    _logger.severe('Error deleting document: $e', e, stackTrace);
    rethrow;
  }
}