Friday, 7 April 2017

grunt task to copy folder runs forever

I am using the module 'archiver' to create a copy of a directory. When I ran the command 'node compressFolder.js' in the command line it finished correctly in about 3 seconds, but when using the following grunt task it ran for 18 minutes without finishing. When I ran from the command line this file was a little bit different (because in that file the links were relative to compressFolder.js, but since I am now using grunt it is now relative to Gruntfile.js):

//todo: grunt task testing:zipTestDir ran for 18m without completing but when run with node completes in ~3s

//require modules
var fs = require('fs');
var archiver = require('archiver');

var dirName = './test/compressionTest';
var date = new Date();
var timeStamp = date.getMonth() + 1 + '-' + date.getDate() + '-' + date.getFullYear() + '-' +
    date.getHours() + 'h' + date.getMinutes() + 'm' + date.getSeconds() + 's' + date.getMilliseconds() + 'ms';

// create a file to stream archive data to.
var output = fs.createWriteStream(dirName + '/' + timeStamp + '.zip');
var archive = archiver('zip', {
    store: true // Sets the compression method to STORE.
});

// listen for all archive data to be written
output.on('close', function() {
    console.log(archive.pointer() + ' total bytes');
    console.log('archiver has been finalized and the output file descriptor has closed.');
});

// good practice to catch this error explicitly
archive.on('error', function(err) {
    throw err;
});

// pipe archive data to the file
archive.pipe(output);

//append files from a directory
archive.directory('.//test');

//finalize the archive (ie we are done appending files but streams have to finish yet)
archive.finalize();



via John123