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

@triniwiz/nativescript-downloader

v3.1.0

Published

Download Manager for NativeScript

Downloads

408

Readme

Nativescript Downloader

Installation

npm install @triniwiz/nativescript-downloader

Usage

TypeScript

import { Downloader } from '@triniwiz/nativescript-downloader';
Downloader.setTimeout(120); //Increase timeout default 60s
import { Downloader, ProgressEventData, DownloadEventData } from 'nativescript-downloader';
const downloader = new Downloader();
const imageDownloaderId = Downloader.createDownload({
  url:
    'https://wallpaperscraft.com/image/hulk_wolverine_x_men_marvel_comics_art_99032_3840x2400.jpg'
});

downloader
  .start(imageDownloaderId, (progressData: ProgressEventData) => {
    console.log(`Progress : ${progressData.value}%`);
    console.log(`Current Size : ${progressData.currentSize}%`);
    console.log(`Total Size : ${progressData.totalSize}%`);
    console.log(`Download Speed in bytes : ${progressData.speed}%`);
  })
  .then((completed: DownloadEventData) => {
    console.log(`Image : ${completed.path}`);
  })
  .catch(error => {
    console.log(error.message);
  });

JavaScript

var Downloader = require('@triniwiz/nativescript-downloader').Downloader;
Downloader.setTimeout(120); //Increase timeout default 60s
var Downloader = require('@triniwiz/nativescript-downloader').Downloader;
var downloader = new Downloader();
var imageDownloaderId = downloadManager.createDownload({
  url:
    'https://wallpaperscraft.com/image/hulk_wolverine_x_men_marvel_comics_art_99032_3840x2400.jpg'
});

downloader
  .start(imageDownloaderId, progressData => {
    console.log(`Progress : ${progressData.value}%`);
  })
  .then(completed => {
    console.log(`Image : ${completed.path}`);
  })
  .catch(error => {
    console.log(error.message);
  });

Api

| Method | Default | Type | Description | | ---------------------------------------- | ------- | ---------------------------- | ----------------------------------------------------- | | createDownload(options: DownloadOptions) | | string | Creates a download task it returns the id of the task | | getStatus(id: string) | | StatusCode | Gets the status of a download task. | | start(id: string, progress?: Function) | | Promise<DownloadEventData> | Starts a download task. | | | resume(id: string) | | void | Resumes a download task. | | cancel(id: string) | | void | Cancels a download task. | | pause(id: string) | | void | Pauses a download task. | | getPath(id: string) | | void | Return the path of a download task. |

Example Image

| IOS | Android | | --------------------------------------- | ------------------------------------------- | | IOS | Android |

Angular

Custom Downloader option

  // Request format for Downlaoder
             DownloadOptions {
             url: string;
             query?: Object | string;
             headers?: Object;
            path?: string;
             fileName?: string;
          }

Service File To use any where

import { Injectable } from '@angular/core';
import { Subject } from 'rxjs';
import { Downloader, ProgressEventData, DownloadEventData } from '@triniwiz/nativescript-downloader';



@Injectable({
    providedIn: 'root',
})


export class DataDownLoadService {
    public database: any;
    downloader: Downloader = new Downloader();
    constructor() { }


    /**
    * @ngdoc method
    * @name downloadDb
    * @description  download generic method for nay file 
    * @memberof DataDownLoadService
    * @param apiUrl : - https://myserver.com/mypath
    * @param filename :- myfile.zip ...
    * @param downloadlocation : mobile local location
    */
    downloadFile(apiUrl, filename, downloadlocation) {
        const subject = new Subject<any>();
    
        // Request format for Downlaoder
        //      DownloadOptions {
        //     url: string;
        //     query?: Object | string;
        //     headers?: Object;
        //     path?: string;
        //     fileName?: string;
        //   }

        // Prepare the header with token work
    
        const headerHttp = {
            "Content-Type": "application/json",
            "Authorization": 'Bearer ' + 'Token...'
        }

        const url =  apiUrl;

        const zipDownloaderId = this.downloader.createDownload({
            url: url,
            headers: headerHttp,
            path: downloadlocation,
            fileName: filename
        });

        this.downloader
            .start(zipDownloaderId, (progressData: ProgressEventData) => {
                console.log(`Progress : ${progressData.value}%`);
                console.log(`Current Size : ${progressData.currentSize}%`);
                console.log(`Total Size : ${progressData.totalSize}%`);
                console.log(`Download Speed in bytes : ${progressData.speed}%`);
            })
            .then((completed: DownloadEventData) => {
                console.log(`zip file saved at : ${completed.path}`);
              
               
                
                subject.next(true);
              
            })
            .catch(error => {
                console.log('downloadDb', error.message);
                subject.error(error);

            });

        return subject.asObservable();
    }



}

TODO

  • [ ] Local Notifications

Apache License Version 2.0