2017-01-27 10 views
1

インターネットから画像をダウンロードしています(Boxから)、body.lengthとヘッダーcontent-lengthが違ってきています。Nodejs異なるコンテンツの長さ

応答ヘッダーcontent-length75739と同じです。 ただし、body.lengthはと同じです。

request(url).pipe(fs.createWriteStream('image.jpg'))を実行すると画像が75739になり、正常に開きます。

fs.writeFileSync('image.jpg', body)を実行した場合、イメージは137515になり、正しく表示されません。

自分でテストすることができますので、私もこの主旨をした: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

ありがとう!

答えて

1

答えが見つかりました。私の友人に感謝します。リクエストライブラリに問題があるかどうかは分かりませんが、リクエストで{ encoding: 'binary' }と設定すると、すべて正常に動作します。

関連する問題