md5-file | return an md5sum of a given file | Hacking library
kandi X-RAY | md5-file Summary
kandi X-RAY | md5-file Summary
Get the MD5-sum of a given file, with low memory usage, even on huge files.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of md5-file
md5-file Key Features
md5-file Examples and Code Snippets
Community Discussions
Trending Discussions on md5-file
QUESTION
I'm trying to make a simple program in node.js that will download the same file with some interval. If the downloaded file is newer than the previous, then it will be saved in a new filename with the help of a counter.
If it's a new file, then I want to save it in the last_unique.jpg name and use it to compare next time the file will be downloaded. But it doesn't seem to work. For test, I just have an empty last_unique.jpg that I would expect to be overwritten. But it never is, so every time the jpg file is downloaded, it is unique and saves it in file3.jpg, file3.jpg, etc.
However, the output also looks like maybe some async issues? It skips the first couple of times.
OUTPUT:
...ANSWER
Answered 2019-Oct-24 at 11:00const http = require('http');
const fs = require('fs');
const md5File = require('md5-file');
const fileToDownload = "http://i3.ytimg.com/vi/J---aiyznGQ/mqdefault.jpg";
var counter = 0;
function request() {
counter = counter + 1;
console.log("downloading " + counter);
const save = fs.createWriteStream("last_download.jpg");
http.get(fileToDownload, function(response) {
response.pipe(save);
response.on('end',function () {
save.end();
})
});
save.on('finish',function () {
const hash1 = md5File.sync('last_download.jpg');
const hash2 = md5File.sync('last_unique.jpg');
console.log(hash1,hash2);
// it is a new file
if (hash1.localeCompare(hash2) != 0) {
console.log('Unique file spotted!');
fs.copyFileSync('last_download.jpg','last_unique.jpg');
fs.copyFileSync('last_unique.jpg','file' + counter + '.jpg');
}
});
}
setInterval(request, 3000);
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install md5-file
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page