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');
const dirPath = path.join(__dirname, '/temp');
const imgUrl = "https://i.ytimg.com/vi/YQHsXMglC9A/maxresdefault.jpg";
useAndThrow(imgUrl, dirPath, imageHandler);
function imageHandler(err, pathToImage, done) {
if(err){
return done();
}
useTheImage(pathToImage);
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