简体   繁体   中英

Converting byte array to string

I am using ssh2 to execute ls -1 command on remote computer and get response like byte array. I convert to string with function

function ab2str(buf) {
  return String.fromCharCode.apply(null, new Uint16Array(buf));
}

but when I try to split resulted/converted string by newline it doesn't work. (I have tried and asked on stackoverflow how to split and tried all solutions but it doesn't work, different results like add \ at the beginning and similar but doesn't split). I think maybe I convert on wrong way. Did anyone use ssh2 for return and how to convert that array to string.

在你的 buf 上使用Buffer.toString()方法

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM