Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

xdcc

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

xdcc - npm Package Compare versions

Comparing version 0.1.2 to 0.2.0

clannad-vp-patch-20120607.zip

72

example.js
var irc = require('./lib/xdcc').irc;
var ProgressBar = require('progress');
var user = 'desu' + Math.random().toString(36).substr(7, 3);
var hostUser = 'Doki|Kotomi';
var pack = 10;
var meta, bar;
require('crypto').randomBytes(2, function(ex, buf) {
var user = 'user' + buf.toString('hex');
var hostUser = 'Doki|Nanoha';
var pack = 750;
var det;
console.log('Connecting...');
var client = new irc.Client('irc.rizon.net', user, {
channels: [ '#doki' ],
userName: user,
realName: user
});
var client = new irc.Client('irc.rizon.net', user, {
channels: [ '#doki' ],
userName: user,
realName: user
});
client.on('join', function(channel, nick, message) {
if (nick !== user) return;
console.log('Joined', channel);
client.getXdcc(hostUser, 'xdcc send #' + pack, '.');
});
client.on('join', function(channel, nick, message) {
if (nick == user) {
console.log('joined ' + channel);
client.getXdcc(hostUser, 'xdcc send #' + pack, '/home/jli');
}
});
client.on('xdcc-connect', function(_meta) {
meta = _meta;
client.on('xdcc-connect', function(details) {
det = details;
console.log('Connected: ' + details.ip + ':' + details.port);
console.log('Connected: ' + meta.ip + ':' + meta.port);
bar = new ProgressBar('Downloading... [:bar] :percent, :etas remaining', {
incomplete: ' ',
total: meta.length,
width: 20
});
});
client.on('xdcc-data', function(received) {
console.log((received / det.length * 100).toFixed(2) + "%");
});
var last = 0;
client.on('xdcc-data', function(received) {
bar.tick(received - last);
last = received;
});
client.on('xdcc-end', function(received) {
console.log('Done.');
});
client.on('xdcc-end', function(received) {
console.log('Download completed');
});
client.on('notice', function(from, to, message) {
if (to == user && from == hostUser) {
console.log("NOTICE " + message);
}
});
client.on('notice', function(from, to, message) {
if (to == user && from == hostUser) {
console.log("NOTICE " + message);
}
});
client.on('error', function(message) {
console.error(message);
});
client.on('error', function(message) {
console.error(message);
});

@@ -5,2 +5,21 @@ var irc = require('irc')

function uint32ToIP(n) {
var byte1 = n & 255
, byte2 = ((n >> 8) & 255)
, byte3 = ((n >> 16) & 255)
, byte4 = ((n >> 24) & 255);
return byte4 + "." + byte3 + "." + byte2 + "." + byte1;
}
function parseSendParams(text) {
var parts = text.match(/(?:[^\s"]+|"[^"]*")+/g);
return {
file: parts[2],
ip: uint32ToIP(parseInt(parts[3], 10)),
port: parseInt(parts[4], 10),
length: parseInt(parts[5], 10)
};
}
/*

@@ -10,63 +29,55 @@ * `path` is treated as a folder by default

irc.Client.prototype.getXdcc = function(hostUser, hostCommand, path, isFile) {
var self = this, handler;
function parseSendParams(text) {
function uint32ToIP(n) {
var byte1 = n & 255
, byte2 = ((n >> 8) & 255)
, byte3 = ((n >> 16) & 255)
, byte4 = ((n >> 24) & 255);
function detach() {
self.removeListener('ctcp-privmsg', handler);
}
return byte4 + "." + byte3 + "." + byte2 + "." + byte1;
}
self.on('ctcp-privmsg', handler = function(from, to, text) {
if (to !== self.nick || from !== hostUser) return;
detach();
var parts = text.match(/(?:[^\s"]+|"[^"]*")+/g);
return {
file: parts[2],
ip: uint32ToIP(parseInt(parts[3], 10)),
port: parseInt(parts[4], 10),
length: parseInt(parts[5], 10)
};
}
if (text.substr(0, 9) !== 'DCC SEND ') return;
var self = this;
self.say(hostUser, hostCommand);
var filePath = (path + '');
var details = parseSendParams(text);
if (!isFile) {
filePath = filePath + '/' + details.file;
}
self.on('ctcp-privmsg', function(from, to, text) {
if (to == self.nick && from == hostUser) {
if (text.substr(0, 9) == 'DCC SEND ') {
var details = parseSendParams(text);
if (!isFile) {
path = path + '/' + details.file;
}
// Yes, overwrite the file.
var file = fs.createWriteStream(filePath);
// Yes, overwrite the file.
var file = fs.createWriteStream(path);
file.on('open', function() {
var received = 0
, sendBuffer = new Buffer(4);
file.on('open', function() {
var received = 0
, sendBuffer = new Buffer(4);
var client = net.connect(details.port, details.ip, function() {
self.emit('xdcc-connect', details);
});
var client = net.connect(details.port, details.ip, function() {
self.emit('xdcc-connect', details);
});
client.on('data', function(data) {
file.write(data);
received += data.length;
sendBuffer.writeUInt32BE(received, 0);
client.write(sendBuffer);
self.emit('xdcc-data', received);
});
client.on('data', function(data) {
file.write(data);
received += data.length;
sendBuffer.writeUInt32BE(received, 0);
client.write(sendBuffer);
self.emit('xdcc-data', received);
});
client.on('end', function() {
file.end();
self.emit('xdcc-end', received, details);
});
client.on('end', function() {
file.end();
self.emit('xdcc-end', received, details);
});
});
}
}
client.on('error', function(err) {
file.end();
self.emit('xdcc-error', err);
});
});
});
self.once('error', detach);
self.say(hostUser, hostCommand);
};
module.exports.irc = irc;
{
"name": "xdcc"
, "version": "0.1.2"
, "author": "Justin Li <jli@j-li.net>"
, "description": "A simple xdcc client"
, "homepage": "https://github.com/pushrax/node-xdcc"
, "repository": "git://github.com/pushrax/node-xdcc"
, "main": "lib/xdcc"
, "dependencies": {
"irc": "0.3.4"
"name": "xdcc",
"version": "0.2.0",
"author": "Justin Li <jli@j-li.net>",
"description": "A simple xdcc client",
"homepage": "https://github.com/pushrax/node-xdcc",
"repository": "git://github.com/pushrax/node-xdcc",
"main": "lib/xdcc",
"dependencies": {
"irc": "~0.3.6"
}
}

@@ -14,2 +14,3 @@ node-xdcc

See [example.js](https://github.com/pushrax/node-xdcc/blob/master/example.js) for a comprehensive example.
You'll need to `npm install progress` for it to work correctly.
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