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 🙏

© 2024 – Pkg Stats / Ryan Hefner

gopher-lib

v0.2.0

Published

Client, server and utility library for the Gopher Internet protocol.

Downloads

36

Readme

gopher-lib

A node library for communication via the Gopher Internet protocol. Useful for implementing Gopher clients and servers (server class coming soon).

npm install gopher-lib
const Gopher = require('gopher-lib');

var client = new Gopher.Client();

client.get('gopher://gopher.floodgap.com/0/gopher/relevance.txt', (err, reply)=>{
	if(err) {
    	console.error(err);
    } else {
    	console.log(reply.text);
    }
});

API

Class: Server

npm install
./node_modules/jsdoc/jsdoc.js server.js common.js
firefox out/index.html

Class: Client([{timeout: 5000, parseDir: true}])

If timeout is set false, no timeout is used. If parseDir is set false, the directory in the result will be a buffer with the raw text from the server instead of being an Array of GopherResource.

var client = new Gopher.Client();
Method: Client.get(URI|GopherResource, replyHandler [, fileName])

If an URI is used, it must be accepted by GopherResource. If fileName is provided, all received data is streamed directly to the file on disk regardless of type. NOTE: If parseDir===true, then 'i' entries will have all info execpt name stripped before the GopherResource is created.

replyHandler = (err, reply)=>{};

err = Error; // If error is set, reply may contain useful debug information (may).

reply = {
	request: {
    	resource: GopherResource,	// The resource used for making this request
        start: null | Date,			// Request begin time
        stop: null | Date,			// Request end time
        elapsed: null | Integer,	// Elapsed time
        remoteAddress: null | ip,		// The IP address that the host name resolved to
        bytesSent: null | Integer,		// How many bytes were sent to the server
        bytesReceived: null | Integer,	// How many bytes were received from the server
        fileName: null | String,		// If a fileName was given, received data was saved to filaName
    },
    // The following properties are not added if the get method was provided with a fileName.
    directory: null | [GopherResource],		// If res.type is directory or search
    buffer: null | Buffer,					// If res.type is binary file
    text: null | String						// If res.type is text, html or encoded file
};

Class: Resource(URI|[host,port,selector,type,name[,query]])

Valid URI: [gopher://]host[:port][/[type][selector][?query][#name]] Selectors, queries and names can contain spaces or be uriencoded (%20=space) Name will only be set in the resource, it is not used in interaction with the server.

var resourcea = new Gopher.Resource( 'gopher://dusted.dk/0/computers/computers.txt#DusteDs%20computers' );
var resourceb = new Gopher.Resource( 'dusted.dk', '70', '/computers/computers.txt', '0', 'DusteDs computers' );
var resourcec = new Gopher.Resource( 'floodgap.com' );
Method: Resource.toJson()
Method: Resource.toURI()
Method: Resource.toShortURI()
Method: Resource.toDirectoryEntity()
var res = new Gopher.Resource('dusted.dk', '70', Gopher.Types.text, '/pages/about/this_server.txt', 'About my Server');

console.log(res.toJson());
//{"host":"dusted.dk","port":"70","type":"0","selector":"/pages/about/this_server.txt","query":false,"name":"About my Server"}

console.log(res.toURI());
//gopher://dusted.dk:70/0/pages/about/this_server.txt#About%20my%20Server

console.log(res.toShortURI());
//gopher://dusted.dk:70/0/pages/about/this_server.txt

console.log(res.toDirectoryEntity());
//0About my Server    /pages/about/this_server.txt    dusted.dk       70

File: example-client.js

# A simple command-line client for interacting with gopher servers and downloading files.
node example-client.js gopher://dusted.dk/
node example-client.js gopher://dusted.dk/9/pages/goatlove/LD28_GoatLove_linux_b0021.tar.bz2 goatlove.tar.bz2

File: test.js

# Unit test (of the Resource capability to parse a URI)
npm test