feat(compare-files): initial commit
This commit is contained in:
parent
7324a87fbc
commit
ad731ebc29
|
@ -0,0 +1 @@
|
||||||
|
.env*
|
|
@ -0,0 +1,21 @@
|
||||||
|
## Overview
|
||||||
|
Compare files
|
||||||
|
|
||||||
|
## Preparation
|
||||||
|
|
||||||
|
Run the following command in your favorite terminal to install dependenies.
|
||||||
|
```
|
||||||
|
npm i
|
||||||
|
```
|
||||||
|
|
||||||
|
## Development setup
|
||||||
|
|
||||||
|
Run the following command in your favorite terminal if you fancy log messages for debugging.
|
||||||
|
```
|
||||||
|
export DEBUG=$DEBUG,debug
|
||||||
|
```
|
||||||
|
|
||||||
|
Run the following command in your favorite terminal to start the service in development mode.
|
||||||
|
```
|
||||||
|
npm run dev
|
||||||
|
```
|
|
@ -0,0 +1,5 @@
|
||||||
|
/*
|
||||||
|
* SPDX-FileCopyrightText: 2022 Stefan Begerad <stefan@begerad.de>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*/
|
|
@ -0,0 +1,34 @@
|
||||||
|
const debug=require('debug')('files');
|
||||||
|
const fs = require('fs');
|
||||||
|
const fsp = fs.promises;
|
||||||
|
|
||||||
|
//resolves to true or false
|
||||||
|
async function compare(fname1, fname2) {
|
||||||
|
debug('fname1: '+fname1);
|
||||||
|
let h1, h2;
|
||||||
|
try {
|
||||||
|
h1 = await fsp.open(fname1);
|
||||||
|
h2 = await fsp.open(fname2);
|
||||||
|
const [stat1, stat2] = await Promise.all([h1.stat(), h2.stat()]);
|
||||||
|
if (stat1.size !== stat2.size) {
|
||||||
|
debug('file size NOT equal');
|
||||||
|
return false;
|
||||||
|
}else{
|
||||||
|
debug('file size equal');
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
if (h1) {
|
||||||
|
debug('h1 to be closed');
|
||||||
|
await h1.close();
|
||||||
|
}
|
||||||
|
if (h2) {
|
||||||
|
debug('h2 to be closed');
|
||||||
|
await h2.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports={
|
||||||
|
compare
|
||||||
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
const debug=require('debug')('debug');
|
||||||
|
const fs = require('fs');
|
||||||
|
const files=require('./files');
|
||||||
|
const path='/home/begerad/git/sib/sandbox-node/request';
|
||||||
|
const filePathAbsOne=path+'/connect-top-dhid-1654510162870.zip';
|
||||||
|
debug('filePathAbsOne: '+filePathAbsOne);
|
||||||
|
const filePathAbsTwo=path+'/connect-top-dhid-1654514173016.zip';
|
||||||
|
debug('filePathAbsTwo: '+filePathAbsTwo);
|
||||||
|
|
||||||
|
//sample usage
|
||||||
|
files.compare(filePathAbsOne,filePathAbsTwo).then(result => {
|
||||||
|
debug('result: '+result);
|
||||||
|
}).catch(err => {
|
||||||
|
console.log(err);
|
||||||
|
});
|
||||||
|
debug('done.');
|
|
@ -0,0 +1,21 @@
|
||||||
|
{
|
||||||
|
"private": true,
|
||||||
|
"name": "compare-files",
|
||||||
|
"version": "0.0.1",
|
||||||
|
"description": "",
|
||||||
|
"main": "index.js",
|
||||||
|
"scripts": {
|
||||||
|
"dev": "nodemon index.js",
|
||||||
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
|
},
|
||||||
|
"author": "Stefan Begerad",
|
||||||
|
"license": "GPL-3.0",
|
||||||
|
"devDependencies": {
|
||||||
|
"nodemon": "^2.0.7"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"fs": "0.0.1-security",
|
||||||
|
"http": "0.0.1-security",
|
||||||
|
"request": "^2.88.2"
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue