Simplify import / export response streaming
This commit is contained in:
parent
d67e231431
commit
fc68e59644
2 changed files with 4 additions and 6 deletions
|
@ -3,7 +3,6 @@ use crate::err::Error;
|
||||||
use reqwest::blocking::Client;
|
use reqwest::blocking::Client;
|
||||||
use reqwest::header::CONTENT_TYPE;
|
use reqwest::header::CONTENT_TYPE;
|
||||||
use std::fs::OpenOptions;
|
use std::fs::OpenOptions;
|
||||||
use std::io::copy;
|
|
||||||
|
|
||||||
pub fn init(matches: &clap::ArgMatches) -> Result<(), Error> {
|
pub fn init(matches: &clap::ArgMatches) -> Result<(), Error> {
|
||||||
// Set the default logging level
|
// Set the default logging level
|
||||||
|
@ -21,16 +20,15 @@ pub fn init(matches: &clap::ArgMatches) -> Result<(), Error> {
|
||||||
// Set the correct export URL
|
// Set the correct export URL
|
||||||
let conn = format!("{}/export", conn);
|
let conn = format!("{}/export", conn);
|
||||||
// Export the data from the database
|
// Export the data from the database
|
||||||
let mut res = Client::new()
|
Client::new()
|
||||||
.get(&conn)
|
.get(&conn)
|
||||||
.header(CONTENT_TYPE, "application/octet-stream")
|
.header(CONTENT_TYPE, "application/octet-stream")
|
||||||
.basic_auth(user, Some(pass))
|
.basic_auth(user, Some(pass))
|
||||||
.header("NS", ns)
|
.header("NS", ns)
|
||||||
.header("DB", db)
|
.header("DB", db)
|
||||||
.send()?
|
.send()?
|
||||||
.error_for_status()?;
|
.error_for_status()?
|
||||||
// Copy the export to the file
|
.copy_to(&mut file)?;
|
||||||
copy(&mut res, &mut file)?;
|
|
||||||
// Output a success message
|
// Output a success message
|
||||||
info!(target: LOG, "The SQL file was exported successfully");
|
info!(target: LOG, "The SQL file was exported successfully");
|
||||||
// Everything OK
|
// Everything OK
|
||||||
|
|
|
@ -3,7 +3,7 @@ use crate::err::Error;
|
||||||
use reqwest::blocking::Client;
|
use reqwest::blocking::Client;
|
||||||
use reqwest::header::CONTENT_TYPE;
|
use reqwest::header::CONTENT_TYPE;
|
||||||
use std::fs::OpenOptions;
|
use std::fs::OpenOptions;
|
||||||
use std::io::prelude::*;
|
use std::io::prelude::Read;
|
||||||
|
|
||||||
pub fn init(matches: &clap::ArgMatches) -> Result<(), Error> {
|
pub fn init(matches: &clap::ArgMatches) -> Result<(), Error> {
|
||||||
// Set the default logging level
|
// Set the default logging level
|
||||||
|
|
Loading…
Reference in a new issue