akamai / NetStorageKit-Node

Akamai NetStorage API for Node

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Downloaded files corrupted - binary response encoding missing

aarlaud opened this issue · comments

Hi there,

while using the download method, I have found most of my files (videos and ppt for ex) to be corrupted once stored on disk.
Looking at the code in api-request.js, I could see the writefilesync and didn't see any binary encoding set.
I included 'binary' as 3rd argument in the writefilesync and also set res.setEncoding('binary') before the response data gets added to the local variable.

{.....
var rawData = '';
res.setEncoding('binary');
res
.on('data', (data) => {
rawData += data
})
.on('end', () => {
if (requestArgs.action == 'download') {
.......}

It resolved my problem. Might be worth the exposing this as an option potentially.

Cheers !
Antoine A.

commented

Dear @aarlaud,
I corrected it.
Thank you so much for reporting issue :)