kopia lustrzana https://gitlab.com/rysiekpl/libresilient
cli: basic-integrity plugin bugfix (ref. #66)
rodzic
1d8bcc0d39
commit
6dbffb34f9
|
@ -35,6 +35,7 @@ let binToBase64 = (binary_data) => {
|
|||
let getFileIntegrity = async (path, algos) => {
|
||||
|
||||
var result = []
|
||||
var content = false
|
||||
|
||||
// open the file and get some info on it
|
||||
const file = await Deno.open(
|
||||
|
@ -49,7 +50,7 @@ let getFileIntegrity = async (path, algos) => {
|
|||
//console.log(`+-- reading: ${path}`)
|
||||
|
||||
// initialize
|
||||
var content = new Uint8Array()
|
||||
content = new Uint8Array()
|
||||
var buf = new Uint8Array(1000);
|
||||
|
||||
// read the first batch
|
||||
|
@ -74,20 +75,6 @@ let getFileIntegrity = async (path, algos) => {
|
|||
// read some more
|
||||
numread = file.readSync(buf);
|
||||
}
|
||||
//console.log(' +-- done.')
|
||||
|
||||
//console.log('+-- calculating digests')
|
||||
for (const algo of algos) {
|
||||
//console.log(` +-- ${algo}`)
|
||||
var digest = algo.toLowerCase().replace('-', '') + '-' + binToBase64(await crypto.subtle.digest(algo, content))
|
||||
//console.log(digest)
|
||||
result.push(digest)
|
||||
}
|
||||
//console.log(`+-- file done: ${path}`)
|
||||
|
||||
// we are not working with a file
|
||||
} else {
|
||||
result = false;
|
||||
}
|
||||
|
||||
// putting this in a try-catch block as the file
|
||||
|
@ -97,6 +84,20 @@ let getFileIntegrity = async (path, algos) => {
|
|||
await file.close();
|
||||
} catch (BadResource) {}
|
||||
|
||||
// did we get any content?
|
||||
if (typeof content != "boolean") {
|
||||
for (const algo of algos) {
|
||||
//console.log(` +-- ${algo}`)
|
||||
var digest = algo.toLowerCase().replace('-', '') + '-' + binToBase64(await crypto.subtle.digest(algo, content))
|
||||
//console.log(digest)
|
||||
result.push(digest)
|
||||
}
|
||||
// no content means not a file
|
||||
} else {
|
||||
// so no result
|
||||
result = false
|
||||
}
|
||||
|
||||
// return the result
|
||||
return result
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue