putDocument static method
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;
}
}