Skip to content

Commit 917c78f

Browse files
committed
fix #17
1 parent 2cad2d5 commit 917c78f

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

src/ssh2/private/channel.nim

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import libssh2, types, session, utils
1+
import libssh2, types, session, utils, streams
22

33
proc initChannel*(ssh: SSHClient): SSHChannel =
44
## Establish a generic session channel
@@ -28,31 +28,35 @@ proc read*(channel: SSHChannel): string =
2828
var
2929
buffer: array[0..1024, char]
3030
rc: cint
31+
stream = newStringStream()
3132

3233
while true:
33-
zeroMem(addr buffer, buffer.len)
3434
rc = channel.impl.channel_read(addr buffer, buffer.len)
3535
if rc > 0:
36-
result.add($cast[cstring](addr buffer))
36+
stream.writeData(addr buffer, rc)
3737
elif rc == LIBSSH2_ERROR_EAGAIN:
3838
discard waitsocket(channel.client)
3939
else:
4040
break
41+
stream.setPosition(0)
42+
result = stream.readAll()
4143

4244
proc readError*(channel: SSHChannel): string =
4345
var
4446
buffer: array[0..1024, char]
4547
rc: cint
48+
stream = newStringStream()
4649

4750
while true:
48-
zeroMem(addr buffer, buffer.len)
4951
rc = channel.impl.channel_read_stderr(addr buffer, buffer.len)
5052
if rc > 0:
51-
result.add($cast[cstring](addr buffer))
53+
stream.writeData(addr buffer, rc)
5254
elif rc == LIBSSH2_ERROR_EAGAIN:
5355
discard waitsocket(channel.client)
5456
else:
5557
break
58+
stream.setPosition(0)
59+
result = stream.readAll()
5660

5761
proc close*(channel: SSHChannel): bool =
5862
var rc: cint

ssh2.nimble

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Package
22

3-
version = "0.1.5"
3+
version = "0.1.6"
44
author = "Huy Doan"
55
description = "SSH, SCP and SFTP client for Nim"
66
license = "MIT"

0 commit comments

Comments
 (0)