npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

rgtp

v1.0.0

Published

Node.js bindings for Red Giant Transport Protocol (RGTP) - A revolutionary Layer 4 transport protocol implementing exposure-based data transmission

Readme

RGTP Node.js Bindings

Node.js bindings for the Red Giant Transport Protocol (RGTP) - A revolutionary Layer 4 transport protocol that implements exposure-based data transmission.

🚀 Features

  • Layer 4 Transport Protocol: Direct access to RGTP's raw socket implementation
  • Natural Multicast: One exposure serves unlimited receivers
  • Instant Resume: Stateless chunk-based transfers
  • Adaptive Flow Control: Exposure rate matches receiver capacity
  • No Head-of-Line Blocking: Pull chunks out of order
  • Superior Packet Loss Resilience: Only lost chunks need re-exposure

📦 Installation

npm install rgtp

Requirements:

  • Node.js 14.0.0 or higher
  • Native compilation tools (node-gyp)
  • RGTP C library installed system-wide

🎯 Quick Start

Expose a File (Server)

const rgtp = require('rgtp');

async function exposeFile() {
  const session = new rgtp.Session({
    port: 9999,
    adaptiveMode: true,
    onProgress: (bytesTransferred, totalBytes) => {
      const percent = (bytesTransferred / totalBytes * 100).toFixed(1);
      console.log(`Progress: ${percent}%`);
    }
  });

  try {
    await session.exposeFile('large_file.bin');
    console.log('File exposed successfully!');
    
    await session.waitComplete();
    console.log('Exposure completed!');
    
    const stats = await session.getStats();
    console.log(`Throughput: ${stats.avgThroughputMbps.toFixed(2)} MB/s`);
  } finally {
    session.close();
  }
}

exposeFile().catch(console.error);

Pull a File (Client)

const rgtp = require('rgtp');

async function pullFile() {
  const client = new rgtp.Client({
    timeout: 30000,
    onProgress: (bytesTransferred, totalBytes) => {
      const percent = (bytesTransferred / totalBytes * 100).toFixed(1);
      console.log(`Downloaded: ${percent}%`);
    }
  });

  try {
    await client.pullToFile('192.168.1.100', 9999, 'downloaded.bin');
    console.log('File downloaded successfully!');
    
    const stats = await client.getStats();
    console.log(`Average speed: ${stats.avgThroughputMbps.toFixed(2)} MB/s`);
  } finally {
    client.close();
  }
}

pullFile().catch(console.error);

📚 API Reference

Session Class

The Session class is used to expose data for clients to pull.

Constructor

new rgtp.Session(config?)

Parameters:

  • config (Object, optional): Configuration options
    • chunkSize (number): Chunk size in bytes (0 = auto)
    • exposureRate (number): Initial exposure rate (chunks/sec)
    • adaptiveMode (boolean): Enable adaptive rate control (default: true)
    • port (number): Port number (0 = auto)
    • timeout (number): Operation timeout in milliseconds
    • onProgress (function): Progress callback (bytesTransferred, totalBytes) => void
    • onError (function): Error callback (errorCode, errorMessage) => void

Methods

exposeFile(filename)

Expose a file for pulling.

  • Parameters: filename (string) - Path to file to expose
  • Returns: Promise
waitComplete()

Wait for exposure to complete.

  • Returns: Promise
getStats()

Get current transfer statistics.

  • Returns: Promise
cancel()

Cancel ongoing exposure.

  • Returns: Promise
close()

Close the session and free resources.

Events

  • progress - Emitted during transfer: (bytesTransferred, totalBytes)
  • error - Emitted on errors: (error)
  • close - Emitted when session is closed

Client Class

The Client class is used to pull data from sessions.

Constructor

new rgtp.Client(config?)

Parameters:

  • config (Object, optional): Configuration options
    • chunkSize (number): Chunk size in bytes (0 = auto)
    • adaptiveMode (boolean): Enable adaptive mode (default: true)
    • timeout (number): Operation timeout in milliseconds
    • onProgress (function): Progress callback
    • onError (function): Error callback

Methods

pullToFile(host, port, filename)

Pull data from remote host and save to file.

  • Parameters:
    • host (string) - Remote host address
    • port (number) - Remote port number
    • filename (string) - Output filename
  • Returns: Promise
getStats()

Get current transfer statistics.

  • Returns: Promise
cancel()

Cancel ongoing pull operation.

  • Returns: Promise
close()

Close the client and free resources.

Statistics Object

{
  bytesTransferred: number,     // Bytes successfully transferred
  totalBytes: number,           // Total bytes in transfer
  throughputMbps: number,       // Current throughput in MB/s
  avgThroughputMbps: number,    // Average throughput in MB/s
  chunksTransferred: number,    // Number of chunks transferred
  totalChunks: number,          // Total number of chunks
  retransmissions: number,      // Number of retransmissions
  completionPercent: number,    // Completion percentage (0-100)
  elapsedMs: number,           // Elapsed time in milliseconds
  estimatedRemainingMs: number, // Estimated remaining time
  efficiencyPercent: number     // Transfer efficiency percentage
}

🔧 Configuration Helpers

Network-Optimized Configurations

// LAN configuration (high bandwidth, low latency)
const lanConfig = rgtp.createLANConfig();

// WAN configuration (variable bandwidth, higher latency)
const wanConfig = rgtp.createWANConfig();

// Mobile configuration (limited bandwidth, high latency)
const mobileConfig = rgtp.createMobileConfig();

Convenience Functions

// Send a file (convenience function)
const stats = await rgtp.sendFile('file.bin', { port: 9999 });

// Receive a file (convenience function)
const stats = await rgtp.receiveFile('host', 9999, 'output.bin');

🛠️ Utility Functions

// Get library version
const version = rgtp.getVersion();

// Format bytes for display
const formatted = rgtp.formatBytes(1024 * 1024); // "1.0 MB"

// Format duration for display
const duration = rgtp.formatDuration(65000); // "1m 5s"

🎯 Advanced Usage

Event-Driven Progress Monitoring

const session = new rgtp.Session({ port: 9999 });

session.on('progress', (bytesTransferred, totalBytes) => {
  const percent = (bytesTransferred / totalBytes * 100).toFixed(1);
  console.log(`Progress: ${percent}%`);
});

session.on('error', (error) => {
  console.error('Transfer error:', error.message);
});

session.on('close', () => {
  console.log('Session closed');
});

await session.exposeFile('large_file.bin');

Custom Configuration

const config = {
  chunkSize: 256 * 1024,    // 256KB chunks
  exposureRate: 500,        // 500 chunks/sec
  adaptiveMode: true,       // Enable adaptation
  port: 8080,              // Custom port
  timeout: 60000,          // 60 second timeout
  
  onProgress: (transferred, total) => {
    // Custom progress handling
    updateProgressBar(transferred / total);
  },
  
  onError: (code, message) => {
    // Custom error handling
    logError(`RGTP Error ${code}: ${message}`);
  }
};

const session = new rgtp.Session(config);

Graceful Shutdown

const session = new rgtp.Session({ port: 9999 });

process.on('SIGINT', async () => {
  console.log('Shutting down gracefully...');
  await session.cancel();
  session.close();
  process.exit(0);
});

await session.exposeFile('file.bin');
await session.waitComplete();

🔍 Error Handling

try {
  const client = new rgtp.Client({ timeout: 10000 });
  await client.pullToFile('unreachable-host', 9999, 'output.bin');
} catch (error) {
  if (error.message.includes('timeout')) {
    console.log('Connection timed out');
  } else if (error.message.includes('not found')) {
    console.log('File not found on server');
  } else {
    console.log('Transfer failed:', error.message);
  }
}

🚀 Performance Tips

Optimize for Your Network

// For high-bandwidth LAN
const config = rgtp.createLANConfig();
config.chunkSize = 1024 * 1024; // 1MB chunks
config.exposureRate = 10000;    // High rate

// For unreliable WAN
const config = rgtp.createWANConfig();
config.chunkSize = 64 * 1024;   // 64KB chunks
config.timeout = 60000;         // Longer timeout

// For mobile networks
const config = rgtp.createMobileConfig();
config.chunkSize = 16 * 1024;   // 16KB chunks
config.timeout = 120000;        // Very long timeout

Monitor Performance

const session = new rgtp.Session({ port: 9999 });

// Monitor stats every second
const monitor = setInterval(async () => {
  try {
    const stats = await session.getStats();
    console.log(`Throughput: ${stats.throughputMbps.toFixed(1)} MB/s`);
    console.log(`Efficiency: ${stats.efficiencyPercent.toFixed(1)}%`);
  } catch (error) {
    clearInterval(monitor);
  }
}, 1000);

await session.exposeFile('file.bin');
clearInterval(monitor);

🔗 Integration Examples

Express.js Integration

const express = require('express');
const rgtp = require('rgtp');

const app = express();

app.post('/expose/:filename', async (req, res) => {
  const { filename } = req.params;
  
  try {
    const session = new rgtp.Session({ port: 0 }); // Auto-assign port
    await session.exposeFile(filename);
    
    res.json({ 
      success: true, 
      message: 'File exposed successfully',
      port: session.port 
    });
  } catch (error) {
    res.status(500).json({ 
      success: false, 
      error: error.message 
    });
  }
});

Stream Processing

const { Transform } = require('stream');

class RGTPProgressStream extends Transform {
  constructor(session) {
    super();
    this.session = session;
    
    session.on('progress', (transferred, total) => {
      this.emit('progress', { transferred, total });
    });
  }
  
  _transform(chunk, encoding, callback) {
    // Pass through data while monitoring RGTP progress
    callback(null, chunk);
  }
}

📄 License

MIT License - see LICENSE file for details.

🤝 Contributing

Contributions are welcome! Please see the main RGTP repository for contribution guidelines.

🔗 Links