1.0.1 • Published 7 years ago

download-use-throw v1.0.1

Weekly downloads
1
License
MIT
Repository
github
Last release
7 years ago

download-use-throw

Download something - use it - finally delete it

npm Build Status styled with prettier npm Built with generator-ts-np

What?

This package helps you to temporarily download an image and apply your method on it. When you are finished using the downloaded content, the image will automatically get deleted.

npm.io

This package is using Nodejs streams, means, more efficient.

Install

npm i --save download-use-throw

Usage

const useAndThrow = require('download-use-throw');
const path = require('path');

// path to the directory to which
// images are temporarily downloaded
const dirPath = path.join(__dirname, '/temp');

// url of the image to be downloaded
const imgUrl = "https://i.ytimg.com/vi/YQHsXMglC9A/maxresdefault.jpg";

// use and throw
useAndThrow(imgUrl, dirPath, imageHandler);

// function to apply on the downloaded image
function imageHandler(err, pathToImage, done) {
    if(err){
        // handle err

        return done(); // call to done will trigger the deletion process.
    }

    // use the image
    useTheImage(pathToImage); // your function
    // ...
    // ...
    // ...

    // when you finished using the image, call done()
    // which will trigger the deletion process
    done();
}

Call done() when you finished using the image, or you finished handling errors. It will initiate the deletion process.

Unclear about something? Please rise an issue. Please report any issues at github.

used version of ts-np generator

Licence

MIT © Vajahath Ahmed

1.0.1

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago