@1-/scan 0.1.11 → 0.1.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -6
- package/dbInit.js +13 -17
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -31,12 +31,12 @@ npm install @1-/scan
|
|
|
31
31
|
Basic usage:
|
|
32
32
|
|
|
33
33
|
```javascript
|
|
34
|
-
import scan from
|
|
34
|
+
import scan from "@1-/scan";
|
|
35
35
|
|
|
36
36
|
// Scan directory and get update list
|
|
37
|
-
const [updateFiles, upsert] = await scan(
|
|
37
|
+
const [updateFiles, upsert] = await scan("/path/to/dir", "/path/to/db_dir", ["file1.js", "file2.json"]);
|
|
38
38
|
|
|
39
|
-
console.log(
|
|
39
|
+
console.log("Files that need updating:", updateFiles);
|
|
40
40
|
|
|
41
41
|
// Save the updated metadata to database
|
|
42
42
|
await upsert();
|
|
@@ -63,6 +63,8 @@ The architecture prioritizes efficiency through several key design decisions:
|
|
|
63
63
|
- CSV processing: `@1-/csv`
|
|
64
64
|
- Gitignore management: `@1-/upsert_gitignore`
|
|
65
65
|
- Concurrency control: `@3-/plimit`
|
|
66
|
+
- Integer handling: `@3-/int`
|
|
67
|
+
- Variable byte encoding: `@3-/vb`
|
|
66
68
|
|
|
67
69
|
## Code structure
|
|
68
70
|
|
|
@@ -119,12 +121,12 @@ npm install @1-/scan
|
|
|
119
121
|
基础用法:
|
|
120
122
|
|
|
121
123
|
```javascript
|
|
122
|
-
import scan from
|
|
124
|
+
import scan from "@1-/scan";
|
|
123
125
|
|
|
124
126
|
// 扫描目录并获取更新列表
|
|
125
|
-
const [updateFiles, upsert] = await scan(
|
|
127
|
+
const [updateFiles, upsert] = await scan("/path/to/dir", "/path/to/db_dir", ["file1.js", "file2.json"]);
|
|
126
128
|
|
|
127
|
-
console.log(
|
|
129
|
+
console.log("需要更新的文件:", updateFiles);
|
|
128
130
|
|
|
129
131
|
// 将更新后的元数据保存至数据库
|
|
130
132
|
await upsert();
|
|
@@ -151,6 +153,8 @@ await upsert();
|
|
|
151
153
|
- CSV处理:`@1-/csv`
|
|
152
154
|
- Gitignore管理:`@1-/upsert_gitignore`
|
|
153
155
|
- 并发控制:`@3-/plimit`
|
|
156
|
+
- 整数处理:`@3-/int`
|
|
157
|
+
- 可变字节编码:`@3-/vb`
|
|
154
158
|
|
|
155
159
|
## 代码结构
|
|
156
160
|
|
package/dbInit.js
CHANGED
|
@@ -3,16 +3,16 @@ import load from "@1-/csv/load.js";
|
|
|
3
3
|
import upsertGitignore from "@1-/upsert_gitignore";
|
|
4
4
|
import vbE from "@3-/vb/vbE.js";
|
|
5
5
|
import b64Uint8 from "@3-/base64url/b64Uint8.js";
|
|
6
|
+
import int from "@3-/int";
|
|
6
7
|
import { existsSync } from "node:fs";
|
|
7
8
|
import { join, basename } from "node:path";
|
|
8
9
|
import { MTIME, MD5 } from "./const.js";
|
|
9
10
|
|
|
10
|
-
const loadDb = async (
|
|
11
|
-
if (existsSync(
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
});
|
|
11
|
+
const loadDb = async (file_path, db, parseVal) => {
|
|
12
|
+
if (existsSync(file_path)) {
|
|
13
|
+
for (const [path, ...vals] of await load(file_path)) {
|
|
14
|
+
db.set(b64Uint8(path), parseVal(vals));
|
|
15
|
+
}
|
|
16
16
|
}
|
|
17
17
|
};
|
|
18
18
|
|
|
@@ -22,23 +22,19 @@ db_dir: 数据库存放目录
|
|
|
22
22
|
返回值: [db_mtime, db_md5]
|
|
23
23
|
*/
|
|
24
24
|
export default async (db_dir) => {
|
|
25
|
-
const
|
|
26
|
-
|
|
25
|
+
const mtime_path = join(db_dir, MTIME + ".csv"),
|
|
26
|
+
md5_path = join(db_dir, MD5 + ".csv");
|
|
27
27
|
|
|
28
|
-
if (
|
|
29
|
-
upsertGitignore(
|
|
30
|
-
join(db_dir, ".gitignore"),
|
|
31
|
-
path_li.map((x) => basename(x)),
|
|
32
|
-
);
|
|
28
|
+
if (!existsSync(mtime_path)) {
|
|
29
|
+
upsertGitignore(join(db_dir, ".gitignore"), [basename(mtime_path)]);
|
|
33
30
|
}
|
|
34
31
|
|
|
35
32
|
const db_mtime = new BinMap(),
|
|
36
|
-
db_md5 = new BinMap()
|
|
37
|
-
[mtime_path, md5_path] = path_li;
|
|
33
|
+
db_md5 = new BinMap();
|
|
38
34
|
|
|
39
35
|
await Promise.all([
|
|
40
|
-
loadDb(mtime_path, db_mtime, ([size, mtime]) => vbE([
|
|
41
|
-
loadDb(md5_path, db_md5, ([
|
|
36
|
+
loadDb(mtime_path, db_mtime, ([size, mtime]) => vbE([int(size), int(mtime)])),
|
|
37
|
+
loadDb(md5_path, db_md5, ([md5]) => b64Uint8(md5)),
|
|
42
38
|
]);
|
|
43
39
|
|
|
44
40
|
return [db_mtime, db_md5];
|