-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
An imgcache.json file is used to store intermediate image data, including hashes. This saves a significant amount of time for subsequent runs of the program that would have had to read every single image into memory again to compute their hashes. Also, test changed to use the process.argv for getting a directory.
- Loading branch information
Math
committed
Jun 10, 2018
1 parent
26b7ad4
commit 0c9b14a
Showing
7 changed files
with
460 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,24 @@ | ||
function isMD5(x) { | ||
return /^[0-9a-f]{32}/.test(x); | ||
} | ||
require('./dupe-image-remover')('./folder', { | ||
const removeDuplicates = require('./dupe-image-remover'); | ||
const directory = process.argv[2] || './folder'; | ||
|
||
const options = { | ||
recursive: false, | ||
exact: false, | ||
tolerance: 0.005, | ||
rename: true, | ||
namePreference(n1, n2) { | ||
return isMD5(n1) ? n1 : isMD5(n2) ? n2 : n1.length > n2.length ? n1 : n2; | ||
} | ||
}).then(results => { | ||
}; | ||
|
||
function isMD5(x) { | ||
return /^[0-9a-f]{32}/.test(x); | ||
} | ||
function saveResults(results) { | ||
require('fs').writeFile('./results.json', JSON.stringify(results), function(err) { | ||
if (err) console.log(results); | ||
else console.log('Data saved to results.json'); | ||
}); | ||
}); | ||
} | ||
|
||
removeDuplicates(directory, options).then(saveResults); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
const FilePromise = require('./FilePromise'); | ||
|
||
class Cache { | ||
constructor(directory, name) { | ||
this.path = FilePromise.join(directory, name + '.json'); | ||
this.data = {}; | ||
if (FilePromise.existsSync(this.path)) { | ||
this.load(); | ||
} | ||
} | ||
load() { | ||
this.data = FilePromise.readSync(this.path); | ||
} | ||
save() { | ||
return FilePromise.create(this.path, this.data); | ||
} | ||
has(filename) { | ||
return filename in this.data; | ||
} | ||
set(filename, data) { | ||
this.data[filename] = data; | ||
return this.save(); | ||
} | ||
get(filename) { | ||
return this.data[filename]; | ||
} | ||
delete(filename) { | ||
delete this.data[filename]; | ||
return this.save(); | ||
} | ||
replace(oldFilename, newFilename) { | ||
this.data[newFilename] = this.data[oldFilename]; | ||
delete this.data[oldFilename]; | ||
return this.save(); | ||
} | ||
} | ||
|
||
module.exports = Cache; |
Oops, something went wrong.