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::{
|
use std::{
|
||||||
|
io::Read,
|
||||||
sync::mpsc::{self, Receiver, Sender},
|
sync::mpsc::{self, Receiver, Sender},
|
||||||
time::Duration,
|
time::Duration,
|
||||||
};
|
};
|
||||||
|
|
||||||
use bollard::{
|
use bollard::{
|
||||||
container::{
|
container::{
|
||||||
CreateContainerOptions, ListContainersOptions, LogOutput, RemoveContainerOptions,
|
CreateContainerOptions, DownloadFromContainerOptions, ListContainersOptions, LogOutput,
|
||||||
UploadToContainerOptions,
|
RemoveContainerOptions, UploadToContainerOptions,
|
||||||
},
|
},
|
||||||
exec::{CreateExecOptions, StartExecResults},
|
exec::{CreateExecOptions, StartExecResults},
|
||||||
service::ContainerSummary,
|
service::ContainerSummary,
|
||||||
@ -172,6 +174,18 @@ impl Container {
|
|||||||
return None;
|
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) {
|
pub async fn upload_file(&self, content: &str, file_name: String) {
|
||||||
let docker = Docker::connect_with_local_defaults().unwrap();
|
let docker = Docker::connect_with_local_defaults().unwrap();
|
||||||
let path = self.language.clone().unwrap().get_path(file_name.clone());
|
let path = self.language.clone().unwrap().get_path(file_name.clone());
|
||||||
|
Reference in New Issue
Block a user