Skip to content

Commit 11751f0

Browse files
authored
Merge pull request #37 from NobodyXu/feature/AddNewOptionToSessionBuilder
feature: Add new func SessionBuilder::compression to control compression
2 parents 20ede69 + a72f1f2 commit 11751f0

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/builder.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ pub struct SessionBuilder {
4949
known_hosts_check: KnownHosts,
5050
control_dir: Option<PathBuf>,
5151
config_file: Option<PathBuf>,
52+
compression: Option<bool>,
5253
}
5354

5455
impl Default for SessionBuilder {
@@ -62,6 +63,7 @@ impl Default for SessionBuilder {
6263
known_hosts_check: KnownHosts::Add,
6364
control_dir: None,
6465
config_file: None,
66+
compression: None,
6567
}
6668
}
6769
}
@@ -137,6 +139,21 @@ impl SessionBuilder {
137139
self
138140
}
139141

142+
/// Enable or disable compression (including stdin, stdout, stderr, data
143+
/// for forwarded TCP and unix-domain connections, sftp and scp
144+
/// connections).
145+
///
146+
/// Note that the ssh server can forcibly disable the compression.
147+
///
148+
/// By default, ssh uses configure value set in `~/.ssh/config`.
149+
///
150+
/// If `~/.ssh/config` does not enable compression, then it is disabled
151+
/// by default.
152+
pub fn compression(&mut self, compression: bool) -> &mut Self {
153+
self.compression = Some(compression);
154+
self
155+
}
156+
140157
/// Connect to the host at the given `host` over SSH using process impl, which will
141158
/// spawn a new ssh process for each `Child` created.
142159
///
@@ -277,6 +294,12 @@ impl SessionBuilder {
277294
init.arg("-F").arg(config_file);
278295
}
279296

297+
if let Some(compression) = self.compression {
298+
let arg = if compression { "yes" } else { "no" };
299+
300+
init.arg("-o").arg(format!("Compression={}", arg));
301+
}
302+
280303
init.arg(destination);
281304

282305
// we spawn and immediately wait, because the process is supposed to fork.

src/changelog.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use crate::*;
88
///
99
/// ## Added
1010
/// - Added changelog
11+
/// - Added [`SessionBuilder::compression`]
1112
#[doc(hidden)]
1213
pub mod unreleased {}
1314

0 commit comments

Comments
 (0)