@thi.ng/file-io 0.3.24 → 0.4.0

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # Change Log
2
2
 
3
- - **Last updated**: 2022-12-22T21:47:07Z
3
+ - **Last updated**: 2023-01-10T15:20:18Z
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,19 @@ 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
+ ## [0.4.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/file-io@0.4.0) (2023-01-10)
13
+
14
+ #### 🚀 Features
15
+
16
+ - add readText() encoding opts ([22366c0](https://github.com/thi-ng/umbrella/commit/22366c0))
17
+ - add readBinary(), update pkg exports ([2c647ed](https://github.com/thi-ng/umbrella/commit/2c647ed))
18
+
19
+ ### [0.3.25](https://github.com/thi-ng/umbrella/tree/@thi.ng/file-io@0.3.25) (2022-12-29)
20
+
21
+ #### ♻️ Refactoring
22
+
23
+ - update "no-browser" pkg handling ([0e84f1b](https://github.com/thi-ng/umbrella/commit/0e84f1b))
24
+
12
25
  ## [0.3.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/file-io@0.3.0) (2022-05-20)
13
26
 
14
27
  #### 🚀 Features
package/README.md CHANGED
@@ -43,7 +43,7 @@ For Node.js REPL:
43
43
  const fileIo = await import("@thi.ng/file-io");
44
44
  ```
45
45
 
46
- Package sizes (brotli'd, pre-treeshake): ESM: 997 bytes
46
+ Package sizes (brotli'd, pre-treeshake): ESM: 1.03 KB
47
47
 
48
48
  ## Dependencies
49
49
 
@@ -75,4 +75,4 @@ If this project contributes to an academic publication, please cite it as:
75
75
 
76
76
  ## License
77
77
 
78
- © 2022 Karsten Schmidt // Apache License 2.0
78
+ © 2022 - 2023 Karsten Schmidt // Apache License 2.0
package/index.d.ts CHANGED
@@ -5,6 +5,7 @@ export * from "./files.js";
5
5
  export * from "./hash.js";
6
6
  export * from "./json.js";
7
7
  export * from "./mask.js";
8
+ export * from "./read.js";
8
9
  export * from "./temp.js";
9
10
  export * from "./text.js";
10
11
  export * from "./write.js";
package/index.js CHANGED
@@ -5,6 +5,7 @@ export * from "./files.js";
5
5
  export * from "./hash.js";
6
6
  export * from "./json.js";
7
7
  export * from "./mask.js";
8
+ export * from "./read.js";
8
9
  export * from "./temp.js";
9
10
  export * from "./text.js";
10
11
  export * from "./write.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/file-io",
3
- "version": "0.3.24",
3
+ "version": "0.4.0",
4
4
  "description": "Assorted file I/O utils (with logging support) for NodeJS",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -34,14 +34,14 @@
34
34
  "test": "testament test"
35
35
  },
36
36
  "dependencies": {
37
- "@thi.ng/api": "^8.6.2",
38
- "@thi.ng/checks": "^3.3.6",
39
- "@thi.ng/logger": "^1.4.6",
40
- "@thi.ng/random": "^3.3.20"
37
+ "@thi.ng/api": "^8.6.3",
38
+ "@thi.ng/checks": "^3.3.7",
39
+ "@thi.ng/logger": "^1.4.7",
40
+ "@thi.ng/random": "^3.3.21"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@microsoft/api-extractor": "^7.33.7",
44
- "@thi.ng/testament": "^0.3.8",
44
+ "@thi.ng/testament": "^0.3.9",
45
45
  "rimraf": "^3.0.2",
46
46
  "tools": "^0.0.1",
47
47
  "typedoc": "^0.23.22",
@@ -52,7 +52,8 @@
52
52
  "hash",
53
53
  "json",
54
54
  "logger",
55
- "node-only",
55
+ "nodejs",
56
+ "no-browser",
56
57
  "typescript"
57
58
  ],
58
59
  "publishConfig": {
@@ -94,6 +95,9 @@
94
95
  "./mask": {
95
96
  "default": "./mask.js"
96
97
  },
98
+ "./read": {
99
+ "default": "./read.js"
100
+ },
97
101
  "./temp": {
98
102
  "default": "./temp.js"
99
103
  },
@@ -108,5 +112,5 @@
108
112
  "status": "stable",
109
113
  "year": 2022
110
114
  },
111
- "gitHead": "bc6f7f5e2765bb96fe64db804eaf4b2443b47fc6\n"
115
+ "gitHead": "3f0b3e2a7c82aefc7e46fb4338369836b5e1b8cf\n"
112
116
  }
package/read.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ import type { ILogger } from "@thi.ng/logger";
2
+ /**
3
+ * Reads given file `path` into a byte array.
4
+ *
5
+ * @param path
6
+ * @param logger
7
+ */
8
+ export declare const readBinary: (path: string, logger?: ILogger) => Uint8Array;
9
+ //# sourceMappingURL=read.d.ts.map
package/read.js ADDED
@@ -0,0 +1,12 @@
1
+ import { readFileSync } from "fs";
2
+ /**
3
+ * Reads given file `path` into a byte array.
4
+ *
5
+ * @param path
6
+ * @param logger
7
+ */
8
+ export const readBinary = (path, logger) => {
9
+ logger && logger.debug("reading file:", path);
10
+ const buf = readFileSync(path);
11
+ return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
12
+ };
package/text.d.ts CHANGED
@@ -1,5 +1,14 @@
1
+ /// <reference types="node" />
1
2
  import type { ILogger } from "@thi.ng/logger";
2
- export declare const readText: (path: string, logger?: ILogger) => string;
3
+ /**
4
+ * Reads text from given file `path`, optionally with custom encoding (default:
5
+ * UTF-8).
6
+ *
7
+ * @param path
8
+ * @param logger
9
+ * @param encoding
10
+ */
11
+ export declare const readText: (path: string, logger?: ILogger, encoding?: Extract<BufferEncoding, "ascii" | "latin1" | "utf-8" | "utf-16le" | "ucs-2">) => string;
3
12
  /**
4
13
  * Writes `body` as UTF-8 file to given `path`. If `dryRun` is true (default:
5
14
  * false), the file WON'T be written, however if a `logger` is provided then at
package/text.js CHANGED
@@ -1,9 +1,17 @@
1
1
  import { isArray } from "@thi.ng/checks/is-array";
2
2
  import { readFileSync } from "fs";
3
3
  import { writeFile } from "./write.js";
4
- export const readText = (path, logger) => {
4
+ /**
5
+ * Reads text from given file `path`, optionally with custom encoding (default:
6
+ * UTF-8).
7
+ *
8
+ * @param path
9
+ * @param logger
10
+ * @param encoding
11
+ */
12
+ export const readText = (path, logger, encoding = "utf-8") => {
5
13
  logger && logger.debug("reading file:", path);
6
- return readFileSync(path, "utf-8");
14
+ return readFileSync(path, encoding);
7
15
  };
8
16
  /**
9
17
  * Writes `body` as UTF-8 file to given `path`. If `dryRun` is true (default: