@thi.ng/file-io 2.1.20 → 2.1.22
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/CHANGELOG.md +7 -1
- package/delete.js +2 -2
- package/hash.js +3 -3
- package/package.json +4 -4
- package/read.js +1 -1
- package/temp.js +1 -1
- package/text.js +1 -1
- package/write.js +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
- **Last updated**: 2025-01-
|
|
3
|
+
- **Last updated**: 2025-01-21T11:16:50Z
|
|
4
4
|
- **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
|
|
5
5
|
|
|
6
6
|
All notable changes to this project will be documented in this file.
|
|
@@ -9,6 +9,12 @@ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelin
|
|
|
9
9
|
**Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
|
|
10
10
|
and/or version bumps of transitive dependencies.
|
|
11
11
|
|
|
12
|
+
### [2.1.21](https://github.com/thi-ng/umbrella/tree/@thi.ng/file-io@2.1.21) (2025-01-14)
|
|
13
|
+
|
|
14
|
+
#### ♻️ Refactoring
|
|
15
|
+
|
|
16
|
+
- use optional chaining & nullish coalescing ([c5a0a13](https://github.com/thi-ng/umbrella/commit/c5a0a13))
|
|
17
|
+
|
|
12
18
|
## [2.1.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/file-io@2.1.0) (2024-04-23)
|
|
13
19
|
|
|
14
20
|
#### 🚀 Features
|
package/delete.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { rmSync, unlinkSync } from "node:fs";
|
|
2
2
|
const deleteFile = (path, logger, dryRun = false) => {
|
|
3
|
-
logger
|
|
3
|
+
logger?.info(`${dryRun ? "[dryrun] " : ""}deleting file: ${path}`);
|
|
4
4
|
if (dryRun) return;
|
|
5
5
|
unlinkSync(path);
|
|
6
6
|
};
|
|
7
7
|
const deleteDir = (path, logger, dryRun = false) => {
|
|
8
|
-
logger
|
|
8
|
+
logger?.info(`${dryRun ? "[dryrun] " : ""}deleting file: ${path}`);
|
|
9
9
|
if (dryRun) return;
|
|
10
10
|
rmSync(path, { recursive: true, force: true });
|
|
11
11
|
};
|
package/hash.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
2
|
import { createReadStream } from "node:fs";
|
|
3
3
|
const fileHash = async (path, logger, algo = "sha256") => {
|
|
4
|
-
logger
|
|
4
|
+
logger?.info("reading file:", path);
|
|
5
5
|
return await streamHash(createReadStream(path), logger, algo);
|
|
6
6
|
};
|
|
7
7
|
const streamHash = async (src, logger, algo = "sha256") => {
|
|
8
8
|
const sum = createHash(algo);
|
|
9
9
|
for await (let chunk of src) sum.update(chunk);
|
|
10
10
|
const hash = sum.digest("hex");
|
|
11
|
-
logger
|
|
11
|
+
logger?.info(`${algo} hash: ${hash}`);
|
|
12
12
|
return hash;
|
|
13
13
|
};
|
|
14
14
|
const bufferHash = (src, logger, algo = "sha256") => {
|
|
15
15
|
const hash = createHash(algo).update(src).digest("hex");
|
|
16
|
-
logger
|
|
16
|
+
logger?.info(`${algo} hash: ${hash}`);
|
|
17
17
|
return hash;
|
|
18
18
|
};
|
|
19
19
|
export {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/file-io",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.22",
|
|
4
4
|
"description": "Assorted file I/O utils (with logging support) for NodeJS/Bun",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -41,9 +41,9 @@
|
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"@thi.ng/api": "^8.11.16",
|
|
44
|
-
"@thi.ng/checks": "^3.6.
|
|
44
|
+
"@thi.ng/checks": "^3.6.19",
|
|
45
45
|
"@thi.ng/hex": "^2.3.60",
|
|
46
|
-
"@thi.ng/logger": "^3.0.
|
|
46
|
+
"@thi.ng/logger": "^3.0.27",
|
|
47
47
|
"@thi.ng/random": "^4.1.7"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
@@ -127,5 +127,5 @@
|
|
|
127
127
|
"status": "stable",
|
|
128
128
|
"year": 2022
|
|
129
129
|
},
|
|
130
|
-
"gitHead": "
|
|
130
|
+
"gitHead": "56e7a1724e7b0cb5c41119f60320b6ff0e8a3c1c\n"
|
|
131
131
|
}
|
package/read.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { readFileSync } from "node:fs";
|
|
2
2
|
const readBinary = (path, logger) => {
|
|
3
|
-
logger
|
|
3
|
+
logger?.debug("reading file:", path);
|
|
4
4
|
const buf = readFileSync(path);
|
|
5
5
|
return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
6
6
|
};
|
package/temp.js
CHANGED
|
@@ -6,7 +6,7 @@ import { sep } from "node:path";
|
|
|
6
6
|
import { ensureDirForFile } from "./dir.js";
|
|
7
7
|
const createTempFile = (body, logger, name, ext) => {
|
|
8
8
|
const path = tempFilePath(name, ext);
|
|
9
|
-
logger
|
|
9
|
+
logger?.debug("creating temp file:", path);
|
|
10
10
|
ensureDirForFile(path);
|
|
11
11
|
writeFileSync(path, body, isString(body) ? "utf-8" : void 0);
|
|
12
12
|
return path;
|
package/text.js
CHANGED
|
@@ -2,7 +2,7 @@ import { isArray } from "@thi.ng/checks/is-array";
|
|
|
2
2
|
import { readFileSync } from "node:fs";
|
|
3
3
|
import { writeFile } from "./write.js";
|
|
4
4
|
const readText = (path, logger, encoding = "utf-8") => {
|
|
5
|
-
logger
|
|
5
|
+
logger?.debug("reading file:", path);
|
|
6
6
|
return readFileSync(path, encoding);
|
|
7
7
|
};
|
|
8
8
|
const writeText = (path, body, logger, dryRun = false) => writeFile(
|
package/write.js
CHANGED
|
@@ -2,7 +2,7 @@ import { isString } from "@thi.ng/checks/is-string";
|
|
|
2
2
|
import { writeFileSync } from "node:fs";
|
|
3
3
|
import { ensureDirForFile } from "./dir.js";
|
|
4
4
|
const writeFile = (path, body, opts, logger, dryRun = false) => {
|
|
5
|
-
logger
|
|
5
|
+
logger?.info(`${dryRun ? "[dryrun] " : ""}writing file: ${path}`);
|
|
6
6
|
if (dryRun) return;
|
|
7
7
|
ensureDirForFile(path);
|
|
8
8
|
writeFileSync(path, body, !opts && isString(body) ? "utf-8" : opts);
|