I am trying to send a zip file from a node.js server to a node.js client but when i save the zip it is corrupted and will not open.
I am using adm-zip to zip the file and send to client
app.get('/checkForUpdate', function (req, res) {
var zip = new AdmZip();
zip.addLocalFile("./update.js");
var willSendthis = zip.toBuffer();
res.send(willSendthis);
});
here is my client code
$.ajax({
type: 'GET',
contentType: 'application/json',
data: {version: version},
url: 'http://localhost:3000/checkForUpdate',
success: function (data) {
fs.writeFile("update.zip", data, function(err) {
if(err) {
console.log(err);
} else {
console.log("The file was saved!");
}
});
}
});