@1-/scan 0.1.1 → 0.1.2
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 +16 -14
- package/_.js +4 -4
- package/{fileAll.js → load.js} +1 -1
- package/package.json +1 -1
- package/sqlite.js +2 -2
- /package/{fileWrite.js → save.js} +0 -0
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
<a id="en"></a>
|
|
6
6
|
# @1-/scan : Incrementally scan directory files and track metadata in SQLite
|
|
7
7
|
|
|
8
|
-
Incrementally scans directory files, tracks file sizes and modification times, and synchronizes status into
|
|
8
|
+
Incrementally scans directory files, tracks file sizes and modification times, and synchronizes status into an SQLite database using Bun's native SQLite driver (`bun:sqlite`), returning an array of updated relative paths.
|
|
9
9
|
|
|
10
10
|
## Features
|
|
11
11
|
|
|
@@ -14,6 +14,7 @@ Incrementally scans directory files, tracks file sizes and modification times, a
|
|
|
14
14
|
- Smart Path Key: Stores relative paths not exceeding 16 bytes as raw binary to preserve readability, while hashing longer paths to 16-byte MD5 digests to optimize index performance.
|
|
15
15
|
- Database Synchronization: Synchronizes updates and deletions in a single atomic transaction.
|
|
16
16
|
- Ignore Pattern Support: Integrates ignore rules dynamically during traversal.
|
|
17
|
+
- Native SQLite: Leverages Bun's native, high-performance `bun:sqlite` engine, eliminating external build dependencies.
|
|
17
18
|
|
|
18
19
|
## Usage
|
|
19
20
|
|
|
@@ -35,18 +36,18 @@ Execution flow of modules:
|
|
|
35
36
|
```mermaid
|
|
36
37
|
graph TD
|
|
37
38
|
Entry["_.js (Main)"] -->|Open database| Sqlite[sqlite.js]
|
|
38
|
-
Entry -->|Load existing records|
|
|
39
|
+
Entry -->|Load existing records| Load[load.js]
|
|
39
40
|
Entry -->|Walk and compare| DirWalk[dirWalk.js]
|
|
40
41
|
DirWalk -->|Traverse files| Walk["@1-/walk/walkRelIgnore"]
|
|
41
42
|
DirWalk -->|Optimize keys| Hash[hash.js]
|
|
42
|
-
Entry -->|Apply modifications|
|
|
43
|
-
|
|
43
|
+
Entry -->|Apply modifications| Save[save.js]
|
|
44
|
+
Save -->|Wrap transaction| Trans[trans.js]
|
|
44
45
|
```
|
|
45
46
|
|
|
46
47
|
## Tech Stack
|
|
47
48
|
|
|
48
49
|
- Bun: Runtime and test runner
|
|
49
|
-
- SQLite:
|
|
50
|
+
- Bun SQLite: Bun's built-in high-performance SQLite engine
|
|
50
51
|
- `@1-/walk`: Directory walker with ignore support
|
|
51
52
|
- `@3-/vb`: Variable-length byte encoder
|
|
52
53
|
- `@3-/binmap` / `@3-/binset`: Efficient binary collection structures
|
|
@@ -58,8 +59,8 @@ graph TD
|
|
|
58
59
|
├── src
|
|
59
60
|
│ ├── _.js # Entry point orchestrating the scanning and sync process
|
|
60
61
|
│ ├── dirWalk.js # Recursively scans files and filters modified ones
|
|
61
|
-
│ ├──
|
|
62
|
-
│ ├──
|
|
62
|
+
│ ├── load.js # Retrieves database records and initializes schema
|
|
63
|
+
│ ├── save.js # Performs bulk database inserts and deletes
|
|
63
64
|
│ ├── hash.js # Processes path keys into raw bytes or MD5 digests
|
|
64
65
|
│ ├── sqlite.js # Manages SQLite database connection and disposal
|
|
65
66
|
│ └── trans.js # Wraps operations inside an SQL transaction
|
|
@@ -78,7 +79,7 @@ To optimize space inside the database file, SQLite internally uses variable-leng
|
|
|
78
79
|
<a id="zh"></a>
|
|
79
80
|
# @1-/scan : 增量扫描目录文件并使用 SQLite 记录元数据
|
|
80
81
|
|
|
81
|
-
|
|
82
|
+
基于 Bun 原生的高性能内置 SQLite 数据库(`bun:sqlite`)增量扫描目录,比对并同步文件大小与修改时间,并返回有变更的相对路径数组。
|
|
82
83
|
|
|
83
84
|
## 功能介绍
|
|
84
85
|
|
|
@@ -87,6 +88,7 @@ To optimize space inside the database file, SQLite internally uses variable-leng
|
|
|
87
88
|
- 路径映射:相对路径长度不大于 16 字节时保留原始字节,大于 16 字节时计算为 16 字节 MD5,优化数据库索引。
|
|
88
89
|
- 事务同步:更新与删除操作合并至单次数据库事务,确保一致性。
|
|
89
90
|
- 规则过滤:基于 `@1-/walk` 的忽略规则过滤特定文件与目录。
|
|
91
|
+
- 原生数据库:使用 Bun 内置的 `bun:sqlite`,性能优异且无需安装或编译外部依赖。
|
|
90
92
|
|
|
91
93
|
## 使用演示
|
|
92
94
|
|
|
@@ -108,18 +110,18 @@ console.log(updatedPaths);
|
|
|
108
110
|
```mermaid
|
|
109
111
|
graph TD
|
|
110
112
|
Entry["_.js (主入口)"] -->|打开数据库| Sqlite[sqlite.js]
|
|
111
|
-
Entry -->|载入已有记录|
|
|
113
|
+
Entry -->|载入已有记录| Load[load.js]
|
|
112
114
|
Entry -->|遍历并比对| DirWalk[dirWalk.js]
|
|
113
115
|
DirWalk -->|扫描文件系统| Walk["@1-/walk/walkRelIgnore"]
|
|
114
116
|
DirWalk -->|计算路径哈希| Hash[hash.js]
|
|
115
|
-
Entry -->|写入变更数据|
|
|
116
|
-
|
|
117
|
+
Entry -->|写入变更数据| Save[save.js]
|
|
118
|
+
Save -->|执行事务控制| Trans[trans.js]
|
|
117
119
|
```
|
|
118
120
|
|
|
119
121
|
## 技术栈
|
|
120
122
|
|
|
121
123
|
- Bun:运行环境与测试工具
|
|
122
|
-
- SQLite
|
|
124
|
+
- Bun SQLite:Bun 内置的高性能 SQLite 模块
|
|
123
125
|
- `@1-/walk`:支持忽略规则的目录遍历工具
|
|
124
126
|
- `@3-/vb`:可变长度整型编码器
|
|
125
127
|
- `@3-/binmap` / `@3-/binset`:二进制哈希键容器
|
|
@@ -131,8 +133,8 @@ graph TD
|
|
|
131
133
|
├── src
|
|
132
134
|
│ ├── _.js # 主入口,统筹扫描与同步逻辑
|
|
133
135
|
│ ├── dirWalk.js # 递归遍历目录,比对筛选出变更文件
|
|
134
|
-
│ ├──
|
|
135
|
-
│ ├──
|
|
136
|
+
│ ├── load.js # 读取数据库中全部记录,初始化数据表
|
|
137
|
+
│ ├── save.js # 事务内执行批量插入与删除
|
|
136
138
|
│ ├── hash.js # 计算相对路径哈希值或保留原始字节
|
|
137
139
|
│ ├── sqlite.js # 管理 SQLite 数据库连接及资源释放
|
|
138
140
|
│ └── trans.js # 封装数据库事务控制
|
package/_.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { BinMap } from "@3-/binmap";
|
|
2
2
|
import vbE from "@3-/vb/vbE.js";
|
|
3
3
|
import sqlite from "./sqlite.js";
|
|
4
|
-
import
|
|
4
|
+
import load from "./load.js";
|
|
5
5
|
import dirWalk from "./dirWalk.js";
|
|
6
|
-
import
|
|
6
|
+
import save from "./save.js";
|
|
7
7
|
|
|
8
8
|
export default async (dir, db_path) => {
|
|
9
9
|
using db = sqlite(db_path);
|
|
10
10
|
const existing = new BinMap(),
|
|
11
|
-
db_rows =
|
|
11
|
+
db_rows = load(db);
|
|
12
12
|
|
|
13
13
|
for (const row of db_rows) {
|
|
14
14
|
existing.set(row.hash, vbE([row.size, row.mtime]));
|
|
@@ -22,6 +22,6 @@ export default async (dir, db_path) => {
|
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
save(db, to_update, to_delete);
|
|
26
26
|
return to_update.map(([rel_path]) => rel_path);
|
|
27
27
|
};
|
package/{fileAll.js → load.js}
RENAMED
|
@@ -4,7 +4,7 @@ export default (db) => {
|
|
|
4
4
|
try {
|
|
5
5
|
return db.prepare("SELECT hash,size,mtime FROM file").all();
|
|
6
6
|
} catch (err) {
|
|
7
|
-
if (err.
|
|
7
|
+
if (err.errno === SQLITE_ERROR) {
|
|
8
8
|
db.exec("CREATE TABLE file(hash PRIMARY KEY,size INT UNSIGNED,mtime INT UNSIGNED)");
|
|
9
9
|
return [];
|
|
10
10
|
}
|
package/package.json
CHANGED
package/sqlite.js
CHANGED
|
File without changes
|