Node request not saving zip stream

66 views Asked by At

In node-webkit I'm trying to download a remote file and save it to the same folder as the node executable (Windows)

request({
    url: updateUrl,
    encoding: 'binary',
    method: "HEAD"
}, function(err, headRes) {

    appUpdater.updateSize = headRes.headers['content-length'];

    console.log('Update size', appUpdater.updateSize);

    request
        .get({
            url: updateUrl,
            encoding: 'binary'
        })
        .on('error', function(err) {
            console.log('Error downloading update', err);
        })
        .on('data', function(data) {
            appUpdater.downloadedSize = appUpdater.downloadedSize + data.length;

            console.log(appUpdater.updateSize - appUpdater.downloadedSize);

        })
        .on('close', function(data) {
            console.log('Finished downloading update');
        })
        .pipe(fs.createWriteStream('update.zip'));
});

The download progress in the console log looks absolute fine, it gets all the way to 0. However no file is ever created and the close event is never fired.

0

There are 0 answers