1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
//! htsget response.

mod error;
pub(crate) mod ticket;

pub use self::error::Error;
pub(crate) use self::ticket::Ticket;

use bytes::Bytes;
use futures::Stream;

use super::Client;

/// An htsget response.
#[derive(Debug)]
pub struct Response {
    client: Client,
    id: String,
    ticket: Ticket,
}

impl Response {
    pub(crate) fn new(client: Client, id: String, ticket: Ticket) -> Self {
        Self { client, id, ticket }
    }

    /// Returns the record ID.
    pub fn id(&self) -> &str {
        &self.id
    }

    /// Returns the data from the ticket URLs.
    pub fn chunks(&self) -> impl Stream<Item = crate::Result<Bytes>> + '_ {
        use super::chunks::chunks;
        chunks(&self.client, self.ticket.urls())
    }
}