lib/lib.js
/**
 * Given an array of filenames, return an array of the files' contents,
 *   only if the filename matches a regex
 * @param {Array}    files    an array of the filenames to read
 * @param {Function} callback(Error, Array)
 */
Given an array of filenames, return an array of the files' contents,
only if the filename matches a regex
@param {Array}    files    an array of the filenames to read
@param {Function} callback(Error, Array)
Given an array of filenames return an array of the files ' contents only if the filename matches a regex @param { Array } files an array of the filenames to read @param { Function } callback ( Error Array )
function readStylesheets(files, callback) {
    return async.map(files, function (filename, done) {
        if (filename.match(/^http/)) {
            request(
                filename,
                { headers: {'User-Agent': 'UnCSS', 'Accept-Encoding':'gzip'} }
            ).on('error', done).on('response', function (resp) {
              if (resp.statusCode !== 200) { return done(new Error('Status not 200')); }
              if (resp.headers['content-encoding'] && resp.headers['content-encoding'].indexOf('gzip') !== -1) {
                resp = resp.pipe(zlib.createGunzip());
              }
              var body = '';
              resp.on('data', function (data) { body += data; });
              resp.on('end', function () { return done(null, body); });
              resp.on('error', function (err) { return done(err); });
            });
        } else {
            if (fs.existsSync(filename)) {
                return fs.readFile(filename, 'utf8', done);
            }
            return done(new Error('UnCSS: could not open ' + path.join(process.cwd(), filename)));
        }
    }, function(err, res) {
      for(var i = 0; i < files.length; i++) {
        var banner = '/*** uncss> filename: ' + files[i] + ' ***/\n';
        res[i] = banner + res[i];
      }
      return callback(err, res);
    });
}
function readStylesheets ( files , callback ) { return async . map ( files , function ( filename , done ) { if ( filename . match ( / ^http / ) ) { request ( filename , { headers : { 'User-Agent' : 'UnCSS' , 'Accept-Encoding' : 'gzip' } } ) . on ( 'error' , done ) . on ( 'response' , function ( resp ) { if ( resp . statusCode !== 200 ) { return done ( new Error ( 'Status not 200' ) ) ; } if ( resp . headers [ 'content-encoding' ] && resp . headers [ 'content-encoding' ] . indexOf ( 'gzip' ) !== - 1 ) { resp = resp . pipe ( zlib . createGunzip ( ) ) ; } var body = '' ; resp . on ( 'data' , function ( data ) { body += data ; } ) ; resp . on ( 'end' , function ( ) { return done ( null , body ) ; } ) ; resp . on ( 'error' , function ( err ) { return done ( err ) ; } ) ; } ) ; } else { if ( fs . existsSync ( filename ) ) { return fs . readFile ( filename , 'utf8' , done ) ; } return done ( new Error ( 'UnCSS: could not open ' + path . join ( process . cwd ( ) , filename ) ) ) ; } } , function ( err , res ) { for ( var i = 0 ; i < files . length ; i ++ ) { var banner = '/*** uncss> filename: ' + files [ i ] + ' ***/\n' ; res [ i ] = banner + res [ i ] ; } return callback ( err , res ) ; } ) ; }
Given an array of filenames, return an array of the files' contents,
   only if the filename matches a regex
 @param {Array}    files    an array of the filenames to read
 @param {Function} callback(Error, Array)
Given an array of filenames return an array of the files ' contents only if the filename matches a regex @param { Array } files an array of the filenames to read @param { Function } callback ( Error Array )
// res is an array of the content of each file in files (in the same order) // We append a small banner to keep track of which file we are currently processing // super helpful for debugging