Buffer.prototype.toString 不打印超过 500 个字符

Buffer.prototype.toString doesn't print more than 500 characters

一个 http 请求返回了一个不完整的字符串。

https.get(url, function(res) {
 res.on('data', function(data) {
   translationData = data.toString();
    resolve(translationData);
    })
  });

我不能超过 500 个字符。

我想我的代码含糊不清,但什么会导致这个问题?

我尝试了很多方法,但都失败了。

我在 How to display long messages in logcat 中有类似的东西,但在 nodeJS 中没有比较。

您从 http.get 获得的响应对象是 Stream。 每当接收到 chunk 数据时,都会调用 'data' 事件处理程序。您需要处理所有 'data' 事件并收集它们的负载,直到您获得 'end' 事件才能获得完整的响应。

一个简单的方法是使用 concat-stream module.

var concat = require('concat-stream');
https.get(url, function(res) {
    res.pipe(concat(function(data) {
       // data is the entire response
    }));
}

要了解有关流的更多信息,请阅读子堆栈的 stream handbook