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

file-portals

v1.11.0

Published

File sharing package without the need to use a server.

Downloads

504

Readme

File Portals NPM Downloads

File sharing package without the need to use a server. The objetive is to allow to comunicate servers and webs directly to transfer files.

Installation

npm install file-portals

Node configuration

Tested on node 20

To make it work in node, it is necessary to install a package that implements WebRTC.

Examples:

npm install wrtc

After it, is necessary to set it as global with something similar to this

// @ts-ignore
import * as wrtc from 'wrtc';

Object.assign(globalThis, wrtc);

Usage

First of all you need to create a IFilePeer to connect with other IFilePeer

You have to indicate what type of data will be use to write on filesystem. In this case Buffer

Instanciation

const peerA = new FilePeer(); 
const peerB = new FilePeer(); 

Connect peers

// Get offer
const offer = await peerA.connect() as RTCSessionDescription;
// Answer
const answer = await peerB.connect(offer) as RTCSessionDescription;
// Reply
await peerA.connect(answer);

In a real scenario, you have to exchange offers with a server, mail, QR o another data transport

Exchange candidates

const candidatesA = await peerA.candidates.export();
peerB.candidates.import(candidatesA);

In a real scenario, same as offers

Configure a portal

import { IReader, IWriter, NodeReader, NodeWriter } from 'file-agents';

const reader = new NodeReader('path/where/files/will/be/shared');
const writer = new NodeWriter({ name: 'file-to-share' }); // Forget it at this moment
const portal = new FilePortal(reader, writer, peerA/*, { name: 'Portal', type: 'client' }*/); // Optionally can added a name and a type. By default type is client

Getting files from the other portal

const files = await portalA.files(); // If the other portal is a client, it has to accept the request, it`s a security breach that its parched.

Read from file from the other portal

const [{ uuid }] = await portalA.files();
const readed = await portalA.read(uuid, { start: 0, end: 6 });
const text = await readed.text();

Create a writable on the other portal

const writable = await portalA.create({ name: 'file.txt', size: 6 });

Write on the file in the other side

const text = 'text';
const writable = await portalA.create({ name: 'file.txt', size: text.length });

await portalA.write(writable, new Blob(text.split('')), 0);

Close writable

const text = 'text';
const writable = await portalA.create({ name: 'file.txt', size: text.length });

await portalA.write(writable, new Blob(text.split('')), 0);
await portalA.close(writable);