mirror of
https://github.com/mii443/rs-docker-bot.git
synced 2025-08-22 16:15:40 +00:00
add download from container func
This commit is contained in:
@ -1,12 +1,14 @@
|
||||
use core::slice::SlicePattern;
|
||||
use std::{
|
||||
io::Read,
|
||||
sync::mpsc::{self, Receiver, Sender},
|
||||
time::Duration,
|
||||
};
|
||||
|
||||
use bollard::{
|
||||
container::{
|
||||
CreateContainerOptions, ListContainersOptions, LogOutput, RemoveContainerOptions,
|
||||
UploadToContainerOptions,
|
||||
CreateContainerOptions, DownloadFromContainerOptions, ListContainersOptions, LogOutput,
|
||||
RemoveContainerOptions, UploadToContainerOptions,
|
||||
},
|
||||
exec::{CreateExecOptions, StartExecResults},
|
||||
service::ContainerSummary,
|
||||
@ -172,6 +174,18 @@ impl Container {
|
||||
return None;
|
||||
}
|
||||
|
||||
pub async fn download_file(&self, path: &str) -> Vec<u8> {
|
||||
let docker = Docker::connect_with_local_defaults().unwrap();
|
||||
let options = Some(DownloadFromContainerOptions { path });
|
||||
let mut download = docker.download_from_container(&self.id, options);
|
||||
let mut result: Vec<u8> = vec![];
|
||||
while let Some(Ok(d)) = download.next().await {
|
||||
result.append(&mut d.into());
|
||||
}
|
||||
|
||||
result
|
||||
}
|
||||
|
||||
pub async fn upload_file(&self, content: &str, file_name: String) {
|
||||
let docker = Docker::connect_with_local_defaults().unwrap();
|
||||
let path = self.language.clone().unwrap().get_path(file_name.clone());
|
||||
|
Reference in New Issue
Block a user