Skip to content

Commit

Permalink
add #9 compression support with the compression-level argument when c…
Browse files Browse the repository at this point in the history
…onnecting
  • Loading branch information
Demayl committed Jan 11, 2025
1 parent d5f7e52 commit 2155c9f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion examples/scp-download.raku
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use SSH::LibSSH;

sub MAIN($host, $user, $remote, $local, Int :$port, Str :$password) {
my $session = await SSH::LibSSH.connect(:$host, :$user, :$port, :$password);
my $session = await SSH::LibSSH.connect(:$host, :$user, :$port, :$password, compression-level => 7);
await $session.scp-download($remote, $local);
$session.close;
}
9 changes: 9 additions & 0 deletions lib/SSH/LibSSH.rakumod
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ class SSH::LibSSH {
has Str $.private-key-file;
has Str $.private-key-file-password;
has Int $.timeout;
has UInt $.compression-level where 0 <= * <= 9 = 0;
has LogLevel $!log-level;
has &.on-server-unknown;
has &.on-server-known-changed;
Expand All @@ -204,6 +205,7 @@ class SSH::LibSSH {
Str :$!private-key-file = Str, Str :$!password = Str,
Str :$!private-key-file-password = Str,
Int :$!timeout, LogLevel :$!log-level = None,
UInt :$!compression-level where 0 <= * <= 9 = 0,
:&!on-server-unknown = &default-server-unknown,
:&!on-server-known-changed = &default-server-known-changed,
:&!on-server-found-other = &default-server-found-other) {}
Expand Down Expand Up @@ -249,6 +251,13 @@ class SSH::LibSSH {
CArray[int32].new($!log-level)));
}

if $!compression-level > 0 {
error-check($s,
ssh_options_set_str($s, SSH_OPTIONS_COMPRESSION, "yes")); # ("zlib","[email protected]","none")
error-check($s,
ssh_options_set_int($s, SSH_OPTIONS_COMPRESSION_LEVEL, CArray[int32].new($!compression-level)));
}

my $start-time = now;
my $outcome = error-check($s, ssh_connect($s));
$loop.add-session($s);
Expand Down

0 comments on commit 2155c9f

Please sign in to comment.