Git Product home page Git Product logo

nitpin's Introduction

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.