27 lines
		
	
	
		
			567 B
		
	
	
	
		
			Rust
		
	
	
	
	
	
			
		
		
	
	
			27 lines
		
	
	
		
			567 B
		
	
	
	
		
			Rust
		
	
	
	
	
	
use rocket::{response::{Responder, self}, Request, Response, http::ContentType};
 | 
						|
use std::io::Cursor;
 | 
						|
 | 
						|
 | 
						|
 | 
						|
#[derive(Clone)]
 | 
						|
pub struct PdfStream {
 | 
						|
    data: Vec<u8>,
 | 
						|
}
 | 
						|
 | 
						|
impl PdfStream {
 | 
						|
    pub fn new(data: Vec<u8>) -> PdfStream {
 | 
						|
        PdfStream { data }
 | 
						|
    }
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
#[rocket::async_trait]
 | 
						|
impl<'r> Responder<'r, 'static> for PdfStream {
 | 
						|
    fn respond_to(self, _: &'r Request<'_>) -> response::Result<'static> {
 | 
						|
        Response::build()
 | 
						|
            .header(ContentType::PDF)
 | 
						|
            .sized_body(self.data.len(), Cursor::new(self.data))
 | 
						|
            .ok()
 | 
						|
    }
 | 
						|
}
 |