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

@smash-sdk/downloader

v0.1.1

Published

<p align="center"> <a href="https://api.fromsmash.com/"><img src="https://developer.fromsmash.com/LOGO_SMASH_API.png" align="center" width="135" /></a> <h1 align="center">SmashDownloaderJS - Download library <br>powered by the Smash API & SDK</h1> <

Downloads

8

Readme

SmashDownloaderJS is a simple and easy-to-use JavaScript library for downloading files uploaded via the Smash API & SDK. With SmashDownloaderJS, you can integrate Smash’s file download functionality directly into your workflows.

Table of Contents

Installation

You can install SmashDownloaderJS using npm:

npm install @smash-sdk/downloader

Usage

Importing the library

// Using ES6 module
import { SmashDownloader } from '@smash-sdk/downloader';

// Or using CommonJS module
const { SmashDownloader } = require('@smash-sdk/downloader');

Creating an instance

const downloader = new SmashDownloader({
    token: "Your Smash API key here",
    url: 'https://fromsmash.com/transfer-id-example',
    path: "./my_directory/dummy.zip",
});

The available parameters are:

  • token (required): The access token used to authenticate with the Smash API.
  • path (optional): The output directory for the downloaded file. Defaults to the current working directory.
  • url (optional): The URL of the Smash file you want to download. Should be in the format https://fromsmash.com/{transferId}.
  • transferId (optional): The ID of the Smash transfer containing the file you want to download.
  • fileId (optional): The ID of the Smash file you want to download.
  • stream (optional): A writable stream to pipe the file to instead of saving it to disk.
  • enableOverride (optional): A boolean indicating whether to overwrite an existing file with the same name. Defaults to false.
  • password (optional): The password for the Smash transfer, if it is password-protected.

Simple usage example

import { SmashDownloader } from '@smash-sdk/downloader';
import fs from 'fs';

const downloader = new SmashDownloader({
  token: 'my-access-token',
  url: 'https://fromsmash.com/transfer-id-example',
  // or transferId: 'transfer-id-example' (if you don't want to use the URL)
});

downloader.download().then((output) => {
  fs.writeFileSync(output.path, output.buffer);
  console.log(`Downloaded ${output.size} bytes to ${output.path}`);
});

Stream usage example

import { SmashDownloader } from '@smash-sdk/downloader';
import fs from 'fs';

const downloader = new SmashDownloader({
  token: 'my-access-token',
  url: 'https://fromsmash.com/transfer-id-example',
});

const writeStream = fs.createWriteStream('downloaded-file.txt');

downloader.download().then((output) => {
  const readStream = fs.createReadStream(output.path);
  readStream.pipe(writeStream);
  console.log(`Downloaded ${output.size} bytes to stream`);
});

download(): Promise<DownloaderOutput>

Downloads the file from the Smash transfer and returns a Promise that resolves to an object with the following properties:

  • transferId: The ID of the Smash transfer containing the downloaded file.
  • name (optional): The name of the downloaded file.
  • fileId (optional): The ID of the downloaded file.
  • fileName (optional): The name of the downloaded file, including its extension.
  • extension (optional): The extension of the downloaded file.
  • path (optional): The absolute path of the downloaded file.
  • size: The size of the downloaded file, in bytes.
  • availabilityEndDate: The date when the Smash transfer will expire.
  • region: The region where the Smash transfer was created.
  • availabilityDuration: The duration of the Smash transfer, in seconds.
  • filesNumber: The number of files contained in the Smash transfer.
  • created: The date when the Smash transfer was created.
  • availabilityStartDate: The date when the Smash transfer became available.
  • transferUrl: The URL of the Smash transfer.

Events

progress event

import { SmashDownloader } from '@smash-sdk/downloader';

const downloader = new SmashDownloader({
  token: 'my-access-token',
  url: 'https://fromsmash.com/example',
});

downloader.on('progress', (event) => {
  console.log(`Downloaded ${event.data.downloadedSize} of ${event.data.size} bytes`);
});

downloader.download().then((output) => {
  console.log(`Downloaded ${output.size} bytes to ${output.path}`);
}).catch((err) => {
  console.error(`Error downloading file: ${err.message}`);
});

The progress event is emitted while the file is being downloaded, and provides information about the progress of the download. The event object has the following properties:

  • name: The name of the event (progress).
  • data: An object containing information about the download progress. The available properties are:
    • size: The total size of the file being downloaded, in bytes.
    • downloadedSize: The number of bytes that have been downloaded so far.

API Reference

Please refer to the API documentation for more information on the available methods and options.

Examples

You can find example usage and integration of SmashDownloaderJS in the examples folder.

Contributing

Contibutions are welcome! If you'd like to help improving the SmashDownloaderJS, please fork the repository, make your changes, and submit a pull request.

License

SmashDownloaderJS is released under the MIT License.