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

upfile-builder

v0.0.5

Published

Build UFS(Up File System) transactions

Downloads

1

Readme

upfile-builder

Powered by Upfile protocol

Upload files into the BitcoinSV blockchain network with Upfile-builder

Upfile-builder is a package from the Upfile project which allows the services to upload files into the BSV blockchain. The Upfile-builder creates the required outputs for the transaction(s) and passes them to a handler. The handler is responsible for making the payment, broadcasting the transaction(s), and returning the transaction ID. This ID is the key to finding all the transactions. Below is an example that uses the upfile-builder with Handcash connect as a handler.

npm install upfile-builder
npm install @handcash/handcash-connect

First, import a handler(in this example handcash-connect) to handle the payments and the transactions broadcasts.

const { HandCashConnect } = require('@handcash/handcash-connect');

const authToken = 'AUTH_TOKEN'; // Replace with your auth token
const handcash = new HandCashConnect({
  appId: 'APP_ID', // Replace with your app id
  appSecret: 'APP_SECRET' // Replace with your app secret
});

async function payScriptHandler(script) {
  const account = handcash.getAccountFromAuthToken(authToken);
  const paymentParameters = {
    payments: [],
    attachment: {
      format: 'hex',
      value: script
    }
  };

  const result = await account.wallet.pay(paymentParameters);
  console.log(result); // to see the upload process in the console

  if (result && result.transactionId) {
    return result.transactionId;
  }
  throw result;
}

Now, use upfile-builder to make chunks of data to pass to the handler

// Import upfile-builder to upload files into BSV blockchain.
const { write } = require('upfile-builder'); // Import the module
const filePath = '/path/to/the/file/IMG_1866.JPG'; //Path of the file(any format)
const fileName = 'IMG_1866.JPG'; //The file name Shown in the transaction
const description = 'some description'; //Optional

// specify the transaction chunk size in bytes(size of each transaction if the file is more than chunk size)
// the smaller chunks will increase the number of the transactions but it will provide a better streaming when downloading big files like videos, etc.
const chunkSize = 50 * 1024; //50KB
const mimeType = 'auto'; //Auto set of mimetype by the file extension

async function main() {
  // Upload the file by passing it to the handler function and wait for the result;
  const result = await write(
    filePath,
    fileName,
    mimeType,
    chunkSize,
    description,
    payScriptHandler
  );

  console.log(result);
}

main();

/*
Result:
{
  key: '0f6f603b18f87921c28cc1ab1ac0f4028449aca6be26bd9d5cda388e0e22d648',
  filename: 'IMG_1866.JPG',
  mime: 'image/jpeg',
  size: 3252913
}

The file can be accessed by hosting Upfile-server or using our instance on https://cdn.upfile.space

i.e. 
https://cdn.upfile.space/<key>
https://cdn.upfile.space/0f6f603b18f87921c28cc1ab1ac0f4028449aca6be26bd9d5cda388e0e22d648
*/