getDocument static method

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

Get a document (client-side)

Implementation

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

    final requestBytes = DocumentFrame.encodeRequest(
      operation: 'GET',
      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 getting document: $e', e, stackTrace);
    rethrow;
  }
}