Exemple #1
0
  request({url: item.href, jar: true}, function (err, res, body) {
    if (err) return callback(err);
    if (res.statusCode !== 200) return callback(new Error('Status code was ' + res.statusCode));
    if (body.length === 0) return callback(new Error('No body was send'));

    SOURCES[item.key] = body;
    startpoint(body).pipe(analyse(item.href, callback));
  });
Exemple #2
0
function TreeParser(html, callback) {
  if (!(this instanceof TreeParser)) return new TreeParser(html, callback);
  TreeBuilder.call(this);
  var self = this;

  this._element = function () {};
  this._end = function () {
    callback(null, self._tree.children[0]);
  };

  startpoint(html).pipe(this);
}
Exemple #3
0
test('typepoint converts arrays', function (t) {
  var values = [
    ['1', 0, true, 5],
    ['2', 0]
  ];

  startpoint(values, {objectMode: true})
    .pipe(typepoint([Number, Date, Boolean, 10]))
    .pipe(endpoint({objectMode: true}, function (err, rows) {
      t.equal(err, null);
      t.deepEqual(rows, [
        [1, new Date(0), true, 10],
        [2, new Date(0), false, 10]
      ]);
      t.end();
    }));
});
Exemple #4
0
test('typepoint converts objects', function (t) {
  var values = [
    {id: '1', time: 0, other: undefined, check: true, const: 5},
    {id: '2', time: 0, other: 'hi'}
  ];

  startpoint(values, {objectMode: true})
    .pipe(typepoint({id: Number, time: Date, check: Boolean, const: 10}))
    .pipe(endpoint({objectMode: true}, function (err, rows) {
      t.equal(err, null);
      t.deepEqual(rows, [
        {id: 1, time: new Date(0), other: undefined, check: true, const: 10},
        {id: 2, time: new Date(0), other: 'hi', check: false, const: 10}
      ]);
      t.end();
    }));
});
Exemple #5
0
test('write call gets relayed to socket', function (t) {
  var socket = new PassThrough();
  var spliter = binarypoint(socket);

  // Since PassThrough is not just a duplex stream but a transform stream
  // the writes will get back to the binarypoint.
  async.parallel({
    bytes: function (done) {
      socket.pipe(endpoint({objectMode: false}, done));
    },
    messages: function (done) {
      spliter.pipe(endpoint({objectMode: true}, done));
    }
  }, function (err, result) {
    t.equal(err || null, null);
    t.equal(result.bytes.toString(), sizeBuffer(5) + 'Hallo' + sizeBuffer(5) + 'World');
    t.equal(result.messages[0].toString(), 'Hallo');
    t.equal(result.messages[1].toString(), 'World');
    t.end();
  });

  startpoint([new Buffer('Hallo'), new Buffer('World')], {objectMode: true})
    .pipe(spliter);
});
Exemple #6
0
ModuleBox.prototype._getMeta = function (dependencies, normal, special, callback) {
  var self = this;

  var latestmtime = 0;
  var specialValues = {};
  var normalValues = {};
  var files = [];

  var allfound = (function walk(dependencies) {
    for (var i = 0; i < dependencies.length; i++) {
      var job = dependencies[i];
      var collection = job.special ? special : normal;
      var values = job.special ? specialValues : normalValues;

      // filepath must be new (not already checked or known)
      if (collection.fetched.indexOf(job.value) !== -1 ||
          values.hasOwnProperty(job.value) === true) {
        continue;
      }

      // If resource hasn't been cached stop now
      var cache = self._getCache(job);
      if (cache === null) return false;

      // Update latestmtime and hashes array
      if (latestmtime < cache.mtime) {
        latestmtime = cache.mtime;
      }

      // Skip future jobs there are the same
      values[job.value] = true;
      // Add this job to the total job list
      files.push(job);

      // Go one level down and stop if just one resource wasn't found
      var deeptfound = walk(cache.dependencies);
      if (!deeptfound) return false;
    }

    return true;
  })(dependencies);

  // If just one resource wasn't found nothing can be predicted
  if (!allfound) {
    return callback(null, {
      'hash': null,
      'mtime': null
    });
  }

  // Sort files to get a consistent hashsum
  //  these hashes will represent the <file> tags
  var hashes = files.sort().map(function (job) {
    return self._getCache(job).hash;
  });

  // Add resolved input to the beginning of the hashes array
  //  this hashsum will represent the meta tags
  hashes.unshift( createResolveBuffer(special.resolve) );
  hashes.unshift( createResolveBuffer(normal.resolve) );

  // Create new hash object
  var longhash = Buffer.concat(hashes);
  startpoint(longhash).pipe(crypto.createHash('sha256')).pipe(endpoint(function (err, hash) {
    if (err) return callback(err, null);

    // Send hash and mtime meta data
    callback(null, {
      'hash': hash.toString('hex'),
      'mtime': latestmtime === 0 ? null : new Date(latestmtime)
    });
  }));
};