require 'sshkit'
require 'sshkit/dsl'
SSHKit::Backend::Netssh.config.ssh_options = {compression: true, compression_level: 9}
on 'localhost' do
  ls_output = capture(:ls, '-l')
endIt outputs:
...
zlib(finalizer): the stream was freed prematurely.
the issue is that sshkit doesn't close the net-ssh connection which then cannot close the zlib stream which has finalizer and complains.
as a workaround
SSHKit::Backend::Netssh.pool.close_connections
can be added thanks to #285
see also net-ssh/net-ssh#284