@1-/scan 0.1.11 → 0.1.12

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.
Files changed (3) hide show
  1. package/README.md +6 -6
  2. package/dbInit.js +13 -17
  3. 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 '@1-/scan';
34
+ import scan from "@1-/scan";
35
35
 
36
36
  // Scan directory and get update list
37
- const [updateFiles, upsert] = await scan('/path/to/dir', '/path/to/db', ['file1.js', 'file2.json']);
37
+ const [updateFiles, upsert] = await scan("/path/to/dir", "/path/to/db", ["file1.js", "file2.json"]);
38
38
 
39
- console.log('Files that need updating:', updateFiles);
39
+ console.log("Files that need updating:", updateFiles);
40
40
 
41
41
  // Save the updated metadata to database
42
42
  await upsert();
@@ -119,12 +119,12 @@ npm install @1-/scan
119
119
  基础用法:
120
120
 
121
121
  ```javascript
122
- import scan from '@1-/scan';
122
+ import scan from "@1-/scan";
123
123
 
124
124
  // 扫描目录并获取更新列表
125
- const [updateFiles, upsert] = await scan('/path/to/dir', '/path/to/db', ['file1.js', 'file2.json']);
125
+ const [updateFiles, upsert] = await scan("/path/to/dir", "/path/to/db", ["file1.js", "file2.json"]);
126
126
 
127
- console.log('需要更新的文件:', updateFiles);
127
+ console.log("需要更新的文件:", updateFiles);
128
128
 
129
129
  // 将更新后的元数据保存至数据库
130
130
  await upsert();
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 (path, db, parseVal) => {
11
- if (existsSync(path)) {
12
- const rows = await load(path);
13
- rows.forEach(([path_str, ...vals]) => {
14
- db.set(b64Uint8(path_str), parseVal(vals));
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 li = [MTIME, MD5],
26
- path_li = li.map((x) => join(db_dir, x + ".csv"));
25
+ const mtime_path = join(db_dir, MTIME + ".csv"),
26
+ md5_path = join(db_dir, MD5 + ".csv");
27
27
 
28
- if (path_li.some((x) => !existsSync(x))) {
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([Number(size), Number(mtime)])),
41
- loadDb(md5_path, db_md5, ([md5_str]) => b64Uint8(md5_str)),
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];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@1-/scan",
3
- "version": "0.1.11",
3
+ "version": "0.1.12",
4
4
  "description": "Incrementally scan directory files and track metadata in SQLite / 增量扫描目录文件并使用 SQLite 记录元数据",
5
5
  "keywords": [
6
6
  "directory",