Nodejs不同的内容长度

我正在从互联网上下载一个图像(来自Box),并且我得到了不同的body.length和头部content-length

响应头的content-length等于75739 。 但是body.length等于72818

现在看看这个,如果我运行request(url).pipe(fs.createWriteStream('image.jpg')) ,图像得到了75739并正确打开。

另外,如果我运行fs.writeFileSync('image.jpg', body) ,图像得到137515,并没有正确打开。

我也做了这个要点,所以你可以自己testing: https : //gist.github.com/Daymannovaes/54663e0718f0ded40285d0666f937179

我不知道是否编码是问题,但我试图得到与所有的编码字节长度,没有一个是正确的大小:

length of the body (ascii) 72818 length of the body (utf8) 137515 length of the body (utf16le) 5636 length of the body (ucs2) 145636 length of the body (base64) 54613 length of the body (latin1) 72818 length of the body (binary) 72818 length of the body (hex) 36409

提前致谢!

我find了答案。 感谢我的一位朋友。 我不知道是否是请求库的错误,但是如果我在请求中设置{ encoding: 'binary' } ,一切正常。