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

@_koii/storage-task-sdk

v1.2.7

Published

## Introduction

Downloads

134

Readme

Koii Storage Client

Introduction

The Koii Storage Client is a JavaScript library that provides functionality for interacting with Koii Storage, allowing users to upload and retrieve files to and from the Koii network.

Installation

You can install the Koii Storage Client library using npm:

npm i @_koii/storage-task-sdk

Usage

To use the Koii Storage Client in your project, import it into your code:

import {KoiiStorageClient} from '@_koii/storage-task-sdk';

Then, create an instance of the KoiiStorageClient class and use its methods to upload and retrieve files from Koii Storage:

const storageClient = KoiiStorageClient.getInstance(options);

// Upload a file
const fileUploadResponse = await storageClient.uploadFile('path/to/file');

// Retrieve a file
const fileBlob = await storageClient.getFile(fileUploadResponse.cid, 'filename');

Constuctor

You can instantiate the KoiiStorageClient class by providing optional parameters:

  • storageTaskId: The ID of the storage task. Defaults to a default task ID if not provided.
  • k2URL: The URL of the K2 network. Defaults to the testnet URL if not provided.
  • debug: Boolean flag indicating whether to enable debugging mode. Defaults to false.
const storageClient = new KoiiStorageClient(storageTaskId?, k2URL?, debug?);

Methods

uploadFile(file: string | File | File[]): Promise

Uploads a file or an array of files to Koii Storage.

  • file: The file(s) to upload. Can be a file path (string), a File object, or an array of File objects.

Returns a promise that resolves to a FileUploadResponse object containing information about the uploaded file(s).

getFile(cid: string, filename: string): Promise

Retrieves a file from Koii Storage.

  • cid: The content identifier (CID) of the file to retrieve.
  • filename: The name of the file to retrieve.

Returns a promise that resolves to a Blob object containing the retrieved file data.

saveBlobAsFile(blob: Blob, filename: string): Promise

Saves a Blob object as a file on the local filesystem.

  • blob: The Blob object to save as a file.
  • filename: The name of the file to save.

Returns a promise that resolves when the file is successfully saved.

To get text from the Blob object, you can use the text() method like this:

const fileContent = await getFile(cid, filename);
console.log(await fileContent.text());

Example

import KoiiStorageClient from 'koii-storage-client';

const storageClient = new KoiiStorageClient();

async function uploadAndRetrieveFile() {
  // Upload a file
  const fileUploadResponse = await storageClient.uploadFile('path/to/file');

  // Retrieve the uploaded file
  const fileBlob = await storageClient.getFile(fileUploadResponse.cid, 'filename');

  // Save the retrieved file locally
  await storageClient.saveBlobAsFile(fileBlob, 'retrieved-file');

  // Incase the retrieved blob is a text/json file
  // Get text from the retrieved file
  const fileContent = await fileBlob.text();
}

uploadAndRetrieveFile();