-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathencrypt.js
39 lines (32 loc) · 1.11 KB
/
encrypt.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const fs = require('fs');
const path = require('path');
function encodeFolderContentsSync(basePath, outputDir) {
const items = fs.readdirSync(basePath);
for (const item of items) {
if (item === '.gitkeep') {
continue;
}
const itemPath = path.join(basePath, item);
const outputItemPath = path.join(outputDir, Buffer.from(item).toString('base64'));
const itemStats = fs.statSync(itemPath);
if (itemStats.isDirectory()) {
try {
fs.mkdirSync(outputItemPath, { recursive: true });
encodeFolderContentsSync(itemPath, outputItemPath);
} catch (err) {
console.error('Error creating directory:', err);
}
} else if (itemStats.isFile()) {
try {
const fileContents = fs.readFileSync(itemPath);
const base64Contents = Buffer.from(fileContents).toString('base64');
fs.writeFileSync(outputItemPath, base64Contents);
} catch (err) {
console.error('Error encoding or writing file:', err);
}
}
}
}
const inputFolder = './clear';
const outputFolder = './data';
encodeFolderContentsSync(inputFolder, outputFolder);