Skip to content

skerit/nitpin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Nitpin

Nitpin is an NNTP (Usenet/Newsgroups) client library written in JavaScript for node.js/io.js.

Install

$ npm install nitpin

Features

  • Handles multiple connections
  • Reaps idle connections after 30 seconds of inactivity
  • Download NZBs & yEnc decoding
  • PAR repairs (requires par2 installed on your system)

Todo

  • Add support for more commands
  • Multi-server support
  • ...

Available command methods

  • getHead (HEAD)
  • getBody (BODY)
  • getArticle (ARTICLE)
  • stat (STAT)
  • over (XZVER/XOVER/OVER)
  • group (GROUP)
  • capabilities (CAPABILITIES)
  • list (LIST ACTIVE [wildmat])

Examples

Create a Nitpin instance

var Nitpin = require('nitpin'),
    server = new Nitpin({
        host: 'news.php.net', // Example uses the open PHP newsgroups server
        user: null,           // Example doesn't need username
        pass: null,           // Nor password
        port: 119,
        secure: false,
        connections: 1        // 1 is the default amount of connections
    });

Get an overview of messages for the given group

// Automatically tries XZVER, falls back to XOVER when not available
server.over('php.doc.nl', 2, 5, function gotMessages(err, messages) {

    console.log(messages[0]);
    // { id: '2',
    // subject: 'test',
    // from: '[email protected] (Derick Rethans)',
    // date: 'Mon, 24 Jun 2002 14:54:22 +0200 (CEST)',
    // 'message-id': '<[email protected]>',
    // references: '',
    // bytes: '',
    // lines: '9',
    // xref: 'php.doc.nl:2' }
});

Get an article

// Get a specific article from a group
server.getArticle('php.doc.nl', '[email protected]', function gotArticle(err, headers, body) {

    console.log(headers);
    // { path: 'news.php.net',
    //  xref: 'news.php.net php.doc.nl',
    //  'return-path': '<[email protected]>',
    //  'mailing-list': 'contact [email protected]; run by ezmlm',
    //  'delivered-to': 'mailing list [email protected]',
    //  received: 'from jdi.jdimedia.nl (jdi.jdimedia.nl [212.204.192.51])\n\tby jdi.jdimedia.nl (8.12.4/8.12.4) with ESMTP id g5OCsM6M021379\r',
    //  'by pb1.pair.com with smtp; 24 jun 2002 12': '53',
    //  'for <[email protected]>; mon, 24 jun 2002 14': '54',
    //  date: 'Mon, 24 Jun 2002 14',
    //  'x-x-sender': '[email protected]',
    //  to: '[email protected]',
    //  'message-id': '<[email protected]>',
    //  'mime-version': '1.0',
    //  'content-type': 'TEXT/PLAIN; charset=US-ASCII',
    //  subject: 'test',
    //  from: '[email protected] (Derick Rethans)' }
});

Get an NZB and stream the contents

This is still in development and needs a lot more refining.

// Parse an NZB: supply a path on this computer or a URL to download from
server.parseNZB('/path/to/file.nzb', function parsed(err, nzb) {

    // PAR files and RAR files are currently triaged into their own properties
    // A stream can be created like this
    nzb.rars.main.stream();

    // The contents of the rar file can be streamed using `arcstream`
    // (Which is not yet a dependency)
    var ArcStream = require('arcstream');
    var archive = new ArcStream();

    archive.addFile(nzb.rars.main.stream(), 'rar');

    for (var i = 0; i < nzb.rars.others.length; i++) {
        archive.addFile(nzb.rars.others[i].stream(), 'rar');
    }

    archive.on('file', function(filename, stream, arcfile) {
        console.log('FOUND FILE:', filename);

        stream.on('end', function() {
            console.log(filename, 'has finished streaming');
        });
    });
});

License

MIT