I am trying to download a file with multiple parts on the server.
1 file => 25 chunks
I am sending a request to the server via Axios and getting a response like this one.
My goal is to send a request for 25 chunks and combine all data into a single file.
My code:- (Getting invalid file)
async function getChunks() {
let i = 0
for (const url of urls) {
try {
const response = await axios.get(url)
if (i !== 0) {
const data = fs.readFileSync(`test.txt`, 'utf8')
console.log(typeof response.data)
fs.writeFileSync('test.txt', data + response.data, 'binary')
} else {
fs.writeFileSync('test.txt', response.data, 'binary')
}
i++
} catch (error) {
console.log(`unable to get chunk ${url}`)
}
}
}