the image database
Former-commit-id: ac868cf24e85a95fd65ddea93ea2324942c2cdb3
This commit is contained in:
19
db/hashtester.js
Normal file
19
db/hashtester.js
Normal file
@@ -0,0 +1,19 @@
|
||||
const md5 = require('md5');
|
||||
const fs = require('fs');
|
||||
|
||||
let filename = '5241-1.png';
|
||||
|
||||
const start = Date.now();
|
||||
|
||||
filename = filename.split('.png')[0];
|
||||
|
||||
const hash = md5(filename);
|
||||
console.log(hash);
|
||||
|
||||
const bucket = hash.substring(0, 4);
|
||||
const file = `./image/${bucket[0]}/${bucket[1]}/${bucket[2]}/${bucket[3]}/${filename}.png`;
|
||||
|
||||
console.log(fs.existsSync(file));
|
||||
|
||||
const delta = Date.now() - start;
|
||||
console.log(`${delta}ms`);
|
||||
3
db/image/0.tar.gz
Normal file
3
db/image/0.tar.gz
Normal file
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:6fb20220571d719c21b348a4fb2697bb25f1d3629e317b93bb12e0d8c29df67e
|
||||
size 969172739
|
||||
3
db/image/1.tar.gz
Normal file
3
db/image/1.tar.gz
Normal file
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:39cce49c2b08db10690e6dbdd5c90d7bd732392645225af3ff01967912592b5b
|
||||
size 978392963
|
||||
3
db/image/2.tar.gz
Normal file
3
db/image/2.tar.gz
Normal file
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:eb76405cb8d491ff883ad57cca2c91bd31d575bac4c7dc2e2629275ed36c253f
|
||||
size 1019840244
|
||||
3
db/image/3.tar.gz
Normal file
3
db/image/3.tar.gz
Normal file
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:4c44991b1d3d5755c7c98428021ccf657c30337424d877ec487371785379e010
|
||||
size 998324354
|
||||
3
db/image/4.tar.gz
Normal file
3
db/image/4.tar.gz
Normal file
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:e2736b022f6b63358f396024799a0642e80762ccd7b75d0382fa92989eacb165
|
||||
size 971438151
|
||||
3
db/image/5.tar.gz
Normal file
3
db/image/5.tar.gz
Normal file
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:44132b34229096d5a393179527af4d673684bf51ce9a69ee8115053bed670159
|
||||
size 1018434330
|
||||
3
db/image/6.tar.gz
Normal file
3
db/image/6.tar.gz
Normal file
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:e1cca83ab09f639000c034e93f431b9f5564391f7348b7c86be6692c7e0db919
|
||||
size 1007458122
|
||||
3
db/image/7.tar.gz
Normal file
3
db/image/7.tar.gz
Normal file
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:8307204d755d62ff4740eccdea82cd7174beffb8bd8f6ec847798a7ae5eec081
|
||||
size 983908427
|
||||
3
db/image/8.tar.gz
Normal file
3
db/image/8.tar.gz
Normal file
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:60e8db8df71be316e8c595fa71681c6c831ef545b038ef375a627cff8ef5a361
|
||||
size 986151083
|
||||
3
db/image/9.tar.gz
Normal file
3
db/image/9.tar.gz
Normal file
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:b4ffbb714f2f07e17aa64323a33000efaf7748c2aab31bda545c7546c824c6b5
|
||||
size 1002302585
|
||||
3
db/image/a.tar.gz
Normal file
3
db/image/a.tar.gz
Normal file
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:15af4d1d35fd8ed60764ed068e3be1293619244e80eea4e672203140ba4a1301
|
||||
size 979253154
|
||||
3
db/image/b.tar.gz
Normal file
3
db/image/b.tar.gz
Normal file
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:868d32ba5b8a8f11f35c27d8f8d1707293674f18830922058d50d325ae9c4004
|
||||
size 1009976899
|
||||
3
db/image/c.tar.gz
Normal file
3
db/image/c.tar.gz
Normal file
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:90f96f74d081679b5279862299a6910a11cbc791d371e95b56c8b56a16e4efb2
|
||||
size 974228333
|
||||
7
db/image/compressor.sh
Normal file
7
db/image/compressor.sh
Normal file
@@ -0,0 +1,7 @@
|
||||
|
||||
for f in *; do
|
||||
if [ -d "$f" ]; then
|
||||
echo $f
|
||||
tar -czvf $f.tar.gz "$f"/
|
||||
fi
|
||||
done
|
||||
3
db/image/d.tar.gz
Normal file
3
db/image/d.tar.gz
Normal file
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:289c78c17f34ecfbfe7aaac3f9756806ae54f4c957018882b2e638d6f5c2b8e5
|
||||
size 1020586118
|
||||
4
db/image/decompressor.sh
Normal file
4
db/image/decompressor.sh
Normal file
@@ -0,0 +1,4 @@
|
||||
|
||||
for d in *.tar.gz ; do
|
||||
tar -xvzf "$d".tar.gz -C some_custom_folder_name
|
||||
done
|
||||
3
db/image/e.tar.gz
Normal file
3
db/image/e.tar.gz
Normal file
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:c1fa91e64c837584894fbdbd6b94b65d672aa4538aea6ee85748e35be30b1403
|
||||
size 1008906926
|
||||
3
db/image/f.tar.gz
Normal file
3
db/image/f.tar.gz
Normal file
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:dfba2d65311ee7b407b69419c837c45f70f0cede955a824bb5722e3f61c04aa3
|
||||
size 998828122
|
||||
47
db/imagesorter.js
Normal file
47
db/imagesorter.js
Normal file
@@ -0,0 +1,47 @@
|
||||
// sorts images
|
||||
// Take the file name `2336p68.png`, which is a Lego "Cockpit Space Nose",
|
||||
// after a simple MD5 hash, the result is:
|
||||
|
||||
// ```text
|
||||
// "d2ef319ea58566b55070e06096165cb8"
|
||||
// ^^^^
|
||||
// ```
|
||||
|
||||
// Using the first four characters in the hash, we can allocate images
|
||||
// into buckets for storage and quick retreval. This acts very similar
|
||||
// to a hash table implemented in the filesystem.
|
||||
|
||||
const md5 = require('md5');
|
||||
const fs = require('fs');
|
||||
|
||||
fs.readdir('./image/', (err, files) => {
|
||||
files.forEach((file) => {
|
||||
file = file.split('.png')[0];
|
||||
const hash = md5(file);
|
||||
const bucket = hash.substring(0, 4);
|
||||
const newFile = `./image/${bucket[0]}/${bucket[1]}/${bucket[2]}/${bucket[3]}/${file}.png`;
|
||||
|
||||
// if directory doesn't exist, create it
|
||||
if (!fs.existsSync(`./image/`)) {
|
||||
fs.mkdirSync(`./image/`);
|
||||
}
|
||||
if (!fs.existsSync(`./image/${bucket[0]}/`)) {
|
||||
fs.mkdirSync(`./image/${bucket[0]}/`);
|
||||
}
|
||||
if (!fs.existsSync(`./image/${bucket[0]}/${bucket[1]}/`)) {
|
||||
fs.mkdirSync(`./image/${bucket[0]}/${bucket[1]}/`);
|
||||
}
|
||||
if (!fs.existsSync(`./image/${bucket[0]}/${bucket[1]}/${bucket[2]}/`)) {
|
||||
fs.mkdirSync(`./image/${bucket[0]}/${bucket[1]}/${bucket[2]}/`);
|
||||
}
|
||||
if (!fs.existsSync(`./image/${bucket[0]}/${bucket[1]}/${bucket[2]}/${bucket[3]}/`)) {
|
||||
fs.mkdirSync(`./image/${bucket[0]}/${bucket[1]}/${bucket[2]}/${bucket[3]}/`);
|
||||
}
|
||||
|
||||
fs.rename(`./image/${file}.png`, newFile, (err) => {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user