download-use-throw
v1.0.1
Published
Download something - use it - finally delete it
Downloads
2
Readme
download-use-throw
Download something - use it - finally delete it
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.
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.
Licence
MIT © Vajahath Ahmed