[英]Nodejs different content-length
我正在从互联网(来自 Box)下载图像,并且得到不同的body.length
和 header content-length
。
响应头content-length
等于75739
。 但body.length
等于72818
。
现在看看这个,如果我运行request(url).pipe(fs.createWriteStream('image.jpg'))
,图像得到 75739 并正确打开。
fs.writeFileSync('image.jpg', body)
,如果我运行fs.writeFileSync('image.jpg', body)
,图像得到 137515 并且不能正确打开。
我也做了这个要点,所以你可以自己测试: https : //gist.github.com/Daymannovaes/54663e0718f0ded40285d0666f937179
我不知道编码是否是问题,但我尝试使用所有编码获取 byteLength,但没有一个是正确的大小:
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
提前致谢!
我找到了答案。 感谢我的一个朋友。 我不知道是否是请求库的错误,但是如果我在请求时设置{ encoding: 'binary' }
,一切正常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.