New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

data-updater

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

data-updater - npm Package Compare versions

Comparing version 1.4.0 to 2.0.0

lib/FileDriver.js

6

dev/test.js

@@ -1,5 +0,7 @@

var DataUpdater = require('../lib/DataUpdater.js');
var dataUpdater = require('../index.js');
var updater = new DataUpdater('test-data.json', 5000);
// var updater = dataUpdater.fromFile('test-data.json', 5000);
var updater = dataUpdater.fromUrl('http://127.0.0.1:1488/test-data.json', 5000);
updater.on('first-update', function(err) {

@@ -6,0 +8,0 @@ console.log('first-update', err);

@@ -1,1 +0,21 @@

module.exports = require('./lib/DataUpdater.js');
var debug = require('debug');
var DataUpdater = require('./lib/DataUpdater.js');
var FileDriver = require('./lib/FileDriver.js');
var UrlDriver = require('./lib/UrlDriver.js');
module.exports = {
_debug: debug('data-updater'),
fromFile: function(file, interval) {
this._debug('fromFile');
return new DataUpdater(FileDriver, file, interval);
},
fromUrl: function(url, interval) {
this._debug('fromUrl');
return new DataUpdater(UrlDriver, url, interval);
}
};
var _ = require('lodash');
var debug = require('debug');
var events = require('events');
var fs = require('fs');
var util = require('util');
var EventEmitter = events.EventEmitter;
function DataUpdater(dataFile, interval) {
function DataUpdater(driverConstructor, driverOptions, interval) {
EventEmitter.call(this);
this._debug = debug('DataUpdater');
this._clearTimeout = clearTimeout;
this._driverConstructor = driverConstructor;
this._driverOptions = driverOptions;
this._driver = null;
this._unref = false;
this._stopped = false;
this._firstUpdate = true;
this._lastCtime = 0;
this._timeoutRef = null;
this._updating = false;
var onReadFile = _.bind(this._onReadFile, this);
this._readFile = _.bind(fs.readFile, fs, dataFile, onReadFile);
var onStat = _.bind(this._onStat, this);
this._stat = _.bind(fs.stat, fs, dataFile, onStat);
var update = _.bind(this._update, this);

@@ -27,8 +22,12 @@ this._updateDelayed = _.partial(setTimeout, update, interval);

util.inherits(DataUpdater, EventEmitter);
var p = Object.create(EventEmitter.prototype);
var p = DataUpdater.prototype;
DataUpdater.prototype = p;
p.start = function() {
p.start = function(cb) {
this._debug('start');
this._driver = new this._driverConstructor(this._driverOptions, this);
if (cb !== undefined) {
this.once('first-update', cb);
}
this._update();

@@ -77,48 +76,23 @@ };

this._updating = true;
this._checkStat();
this._driver._update();
};
p._checkStat = function(cb) {
this._debug('_checkStat');
this._stat();
p._emitError = function(err) {
this._debug('_emitError');
this._updating = false;
this._mayBeEmitFirstUpdate(err);
this.emit('error', err);
this._scheduleUpdate();
};
p._onStat = function(err, stats) {
this._debug('_onStat');
if (err) {
this._updating = false;
this._mayBeEmitFirstUpdate(err);
this.emit('error', err);
this._scheduleUpdate();
return;
}
var time = stats.ctime.getTime();
if (this._lastCtime === time) {
this._updating = false;
this.emit('old');
this._scheduleUpdate();
return;
}
this._lastCtime = time;
this._readFile();
p._emitOld = function() {
this._debug('_emitOld');
this._updating = false;
this.emit('old');
this._scheduleUpdate();
};
p._onReadFile = function(err, dataAsJson) {
this._debug('_onReadFile');
p._emitUpdate = function(data) {
this._debug('_emitUpdate');
this._updating = false;
if (err) {
this._mayBeEmitFirstUpdate(err);
this.emit('error', err);
this._scheduleUpdate();
return;
}
var data = null;
try {
data = this._parse(dataAsJson);
} catch (e) {
this._mayBeEmitFirstUpdate(e);
this.emit('error', e);
this._scheduleUpdate();
return;
}
this._mayBeEmitFirstUpdate();

@@ -125,0 +99,0 @@ this.emit('update', data);

{
"name": "data-updater",
"version": "1.4.0",
"version": "2.0.0",
"description": "",

@@ -13,3 +13,5 @@ "main": "index.js",

"debug": "^2.1.1",
"lodash": "^2.4.1"
"diver": "^1.0.0",
"lodash": "^2.4.1",
"request": "^2.55.0"
},

@@ -16,0 +18,0 @@ "devDependencies": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc