putDocument static method

Future<DocumentFrameResponse> putDocument(
  1. P2PStream stream, {
  2. required PeerId ownerPeerId,
  3. required String path,
  4. required Uint8List content,
  5. String contentType = 'application/json',
  6. String? ifMatch,
  7. DocumentVisibility? visibility,
  8. int? history,
})

Put a document (client-side)

Implementation

static Future<DocumentFrameResponse> putDocument(
  P2PStream stream, {
  required PeerId ownerPeerId,
  required String path,
  required Uint8List content,
  String contentType = 'application/json',
  String? ifMatch,
  DocumentVisibility? visibility,
  int? history,
}) async {
  try {
    final headers = <String, String>{
      'Content-Type': contentType,
    };
    if (ifMatch != null) {
      headers['If-Match'] = ifMatch;
    }

    final requestBytes = DocumentFrame.encodeRequest(
      operation: 'PUT',
      ownerPeerId: ownerPeerId,
      path: path,
      headers: headers,
      body: content,
      visibility: visibility?.name,
      history: history,
    );

    await _writeFrameStatic(stream, requestBytes);

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