manifesto.js
function parseManifest(manifest, docroot, callback)
{
  var inCache = false
    , lines = [];

    // get manifest file data
    fs.readFile(manifest, 'ascii', function(err, data)
    {
      var counter = 0;

      if (err)
      {
        // to prevent sudden continuation
        return callback(err);
      }

      cache[manifest] =
      {
        version: 0,
        files: [],
        manifest: data
      };

      lines = data.split('\n');

      lines.forEach(function(line)
      {
        var match;

        line = line.trim();

        // empty lines
        if (line.substr(0, 1) == '') return;

        // skip comments
        if (line.substr(0, 1) == '#') return;

        // process control keywords
        switch (line)
        {
          case 'CACHE MANIFEST':
          case 'CACHE:':
            inCache = true;
            return;
            break;

          // TODO: Add proper support for fallbacks
          case 'NETWORK:':
          case 'FALLBACK:':
            inCache = false;
            return;
            break;
        }

        // do nothing for network files
        if (!inCache) return;

        // check the file and setup monitoring
        if (!line.match(/^http(s)?:\/\//))
        {
          addWatcher(docroot+line, watcher(manifest), function(added, mtime)
          {
            // undo counter
            counter--;

            if (!added)
            {
              // check if everything is done
              if (counter == 0) callback();
              return;
            }

            if (mtime > cache[manifest].version) cache[manifest].version = mtime;

            cache[manifest].files.push(line);

            // check if everything is done
            if (counter == 0) callback();
          });

          // track inception
          counter++;
        }

      });
    });
}
function parseManifest(manifest, docroot, callback)
{
  var inCache = false
    , lines = [];

    // get manifest file data
    fs.readFile(manifest, 'ascii', function(err, data)
    {
      var counter = 0;

      if (err)
      {
        // to prevent sudden continuation
        return callback(err);
      }

      cache[manifest] =
      {
        version: 0,
        files: [],
        manifest: data
      };

      lines = data.split('\n');

      lines.forEach(function(line)
      {
        var match;

        line = line.trim();

        // empty lines
        if (line.substr(0, 1) == '') return;

        // skip comments
        if (line.substr(0, 1) == '#') return;

        // process control keywords
        switch (line)
        {
          case 'CACHE MANIFEST':
          case 'CACHE:':
            inCache = true;
            return;
            break;

          // TODO: Add proper support for fallbacks
          case 'NETWORK:':
          case 'FALLBACK:':
            inCache = false;
            return;
            break;
        }

        // do nothing for network files
        if (!inCache) return;

        // check the file and setup monitoring
        if (!line.match(/^http(s)?:\/\//))
        {
          addWatcher(docroot+line, watcher(manifest), function(added, mtime)
          {
            // undo counter
            counter--;

            if (!added)
            {
              // check if everything is done
              if (counter == 0) callback();
              return;
            }

            if (mtime > cache[manifest].version) cache[manifest].version = mtime;

            cache[manifest].files.push(line);

            // check if everything is done
            if (counter == 0) callback();
          });

          // track inception
          counter++;
        }

      });
    });
}
function parseManifest ( manifest , docroot , callback ) { var inCache = false , lines = [ ] ; // get manifest file data fs . readFile ( manifest , 'ascii' , function ( err , data ) { var counter = 0 ; if ( err ) { // to prevent sudden continuation return callback ( err ) ; } cache [ manifest ] = { version : 0 , files : [ ] , manifest : data } ; lines = data . split ( '\n' ) ; lines . forEach ( function ( line ) { var match ; line = line . trim ( ) ; // empty lines if ( line . substr ( 0 , 1 ) == '' ) return ; // skip comments if ( line . substr ( 0 , 1 ) == '#' ) return ; // process control keywords switch ( line ) { case 'CACHE MANIFEST' : case 'CACHE:' : inCache = true ; return ; break ; // TODO: Add proper support for fallbacks case 'NETWORK:' : case 'FALLBACK:' : inCache = false ; return ; break ; } // do nothing for network files if ( ! inCache ) return ; // check the file and setup monitoring if ( ! line . match ( / ^http(s)?:\/\/ / ) ) { addWatcher ( docroot + line , watcher ( manifest ) , function ( added , mtime ) { // undo counter counter -- ; if ( ! added ) { // check if everything is done if ( counter == 0 ) callback ( ) ; return ; } if ( mtime > cache [ manifest ] . version ) cache [ manifest ] . version = mtime ; cache [ manifest ] . files . push ( line ) ; // check if everything is done if ( counter == 0 ) callback ( ) ; } ) ; // track inception counter ++ ; } } ) ; } ) ; }
strip cacheable items from the manifest file
strip cacheable items from the manifest file