@procedures/fs 0.60.0 → 0.61.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 +50 -0
- package/README.md +11 -1
- package/dist/procedures/fs/glob.d.ts.map +1 -1
- package/dist/procedures/fs/glob.js +12 -21
- package/dist/procedures/fs/glob.js.map +1 -1
- package/dist/procedures/fs/json.js +2 -2
- package/dist/procedures/fs/json.js.map +1 -1
- package/dist/procedures/fs/read.d.ts +10 -3
- package/dist/procedures/fs/read.d.ts.map +1 -1
- package/dist/procedures/fs/read.js +74 -8
- package/dist/procedures/fs/read.js.map +1 -1
- package/dist/procedures/fs/temp.d.ts +1 -1
- package/dist/procedures/fs/temp.d.ts.map +1 -1
- package/dist/procedures/fs/temp.js +5 -3
- package/dist/procedures/fs/temp.js.map +1 -1
- package/dist/root.d.ts +11 -1
- package/dist/root.d.ts.map +1 -1
- package/dist/root.js +37 -2
- package/dist/root.js.map +1 -1
- package/dist/types.d.ts +4 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +8 -0
- package/dist/types.js.map +1 -1
- package/package.json +3 -2
- package/src/procedures/fs/glob.ts +12 -24
- package/src/procedures/fs/json.ts +2 -2
- package/src/procedures/fs/read.ts +77 -9
- package/src/procedures/fs/temp.ts +5 -3
- package/src/root.ts +36 -2
- package/src/types.ts +12 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,55 @@
|
|
|
1
1
|
# @procedures/fs
|
|
2
2
|
|
|
3
|
+
## 0.61.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 84d9551: The CHANGELOG of 0.60.1 names only the brace groups of `fs.glob` with `dot: true`. Version 0.60.1 also changed three results of `fs.glob` with `dot: true`. Tests hold these results.
|
|
8
|
+
|
|
9
|
+
- A pattern `x/**` also gives the folder `x`, as `fs.glob` without `dot` does.
|
|
10
|
+
- An ignore pattern keeps the walk out of a folder only when it matches the folder or each entry in it. Before 0.60.1, `**/.*` stopped the walk at each folder, and `a/?` stopped it at the folder `a`.
|
|
11
|
+
- A pattern that starts with `./` matches. Before 0.60.1, it matched nothing.
|
|
12
|
+
|
|
13
|
+
Migration for the site and each app: examine each call of `fs.glob` with `dot: true` and a pattern that ends in `/**`. To get the matches of 0.60.0, remove the match that is equal to the folder.
|
|
14
|
+
- Updated dependencies [8506442]
|
|
15
|
+
- Updated dependencies [f9a78f9]
|
|
16
|
+
- Updated dependencies [3eb4b59]
|
|
17
|
+
- @procedures/client@0.61.0
|
|
18
|
+
|
|
19
|
+
## 0.60.1
|
|
20
|
+
|
|
21
|
+
### Patch Changes
|
|
22
|
+
|
|
23
|
+
- 264e6a1: With `dot: true`, `fs.glob` uses the glob matcher of `@mark1russell7/files` for the pattern and each `ignore` entry. A brace group can hold a dot name, for example `{.git,node_modules}`. The matcher knows `*`, `**`, `?`, sets and brace groups.
|
|
24
|
+
- 11fcffb: `fs.temp` makes its folder in the base folder for each prefix. The prefix is only the start of the folder name, so the prefixes `.` and `..` also make a folder in the base folder. With a root, the base folder is `.tmp` of the root.
|
|
25
|
+
- e8e88ac: On Windows, the root check refuses a network or device path of another share before it opens the path.
|
|
26
|
+
|
|
27
|
+
- A path that starts with two slashes (`\\host\share\name`, `//host/share/name`, `\\?\UNC\host\share\name` or `\\.\pipe\name`) is outside the root, unless the root is on the same share. The check gets `FORBIDDEN` with the reason `outside-root` and does not open the path.
|
|
28
|
+
- `realPathIsInside()` gives false for such a path, and the root check of the git procedures does the same.
|
|
29
|
+
- The new function `isOtherShare()` of the entry `@procedures/fs/root` gives this decision.
|
|
30
|
+
- On other systems, nothing changes.
|
|
31
|
+
- a6fd4f3: `fs.read` and `fs.read.json` get the input `maxBytes`, the largest count of bytes that the read loads. `fs.read` also gets `offset` and `length` for a part of a file.
|
|
32
|
+
|
|
33
|
+
- A part larger than `maxBytes` gives a `RangeError` with the code `ERR_FS_FILE_TOO_LARGE`. For a regular file, the error comes before the read.
|
|
34
|
+
- The read loads pieces of 1 MiB from one open file. Thus the limit holds also for a pipe or a file of the system with no size.
|
|
35
|
+
- Without `maxBytes`, the read loads the whole file, as before. The first read over 16 MiB in a process writes one warning.
|
|
36
|
+
|
|
37
|
+
Migration before 0.64.0: version 0.64.0 sets 16 MiB as the default of `maxBytes`. A caller that reads larger files sets `maxBytes` to its own limit.
|
|
38
|
+
- Updated dependencies [beca782]
|
|
39
|
+
- Updated dependencies [6dbc47e]
|
|
40
|
+
- Updated dependencies [663465c]
|
|
41
|
+
- Updated dependencies [66585f5]
|
|
42
|
+
- Updated dependencies [511d820]
|
|
43
|
+
- Updated dependencies [02a7074]
|
|
44
|
+
- Updated dependencies [265f41c]
|
|
45
|
+
- Updated dependencies [a87cdda]
|
|
46
|
+
- Updated dependencies [94b5f88]
|
|
47
|
+
- Updated dependencies [ca23351]
|
|
48
|
+
- Updated dependencies [84e1b25]
|
|
49
|
+
- Updated dependencies [fe6cd23]
|
|
50
|
+
- Updated dependencies [e9b7551]
|
|
51
|
+
- @procedures/client@0.60.1
|
|
52
|
+
|
|
3
53
|
## 0.60.0
|
|
4
54
|
|
|
5
55
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -280,9 +280,14 @@ console.log(result.stats.size);
|
|
|
280
280
|
interface ReadInput {
|
|
281
281
|
path: string; // File path (absolute or relative)
|
|
282
282
|
encoding?: string; // Default: "utf8"
|
|
283
|
+
offset?: number; // The first byte of the part. Default: 0
|
|
284
|
+
length?: number; // The bytes of the part. Default: to the end of the file
|
|
285
|
+
maxBytes?: number; // The largest count of bytes to load
|
|
283
286
|
}
|
|
284
287
|
```
|
|
285
288
|
|
|
289
|
+
A part larger than `maxBytes` gives a `RangeError` with the code `ERR_FS_FILE_TOO_LARGE`. Without `maxBytes`, the first read over 16 MiB in a process writes a warning. Version 0.64.0 sets 16 MiB as the default.
|
|
290
|
+
|
|
286
291
|
**Output:**
|
|
287
292
|
```typescript
|
|
288
293
|
interface ReadOutput {
|
|
@@ -595,6 +600,10 @@ interface MoveOutput {
|
|
|
595
600
|
|
|
596
601
|
Find files matching a glob pattern using the Node.js `fs.glob` API (`node:fs/promises`, requires Node >= 22).
|
|
597
602
|
|
|
603
|
+
With `dot: true`, the walk uses the glob matcher of `@mark1russell7/files`. Each wildcard matches a name that starts with `.`, and a brace group can hold a dot name, for example `{.github,docs}/**`. The matcher knows `*`, `**`, `?`, sets and brace groups.
|
|
604
|
+
|
|
605
|
+
A pattern `x/**` also gives the folder `x`, as without `dot`. An ignore pattern keeps the walk out of a folder only when it matches the folder or each entry in it. A pattern can start with `./`.
|
|
606
|
+
|
|
598
607
|
```typescript
|
|
599
608
|
const result = await client.exec(
|
|
600
609
|
["fs", "glob"],
|
|
@@ -664,6 +673,7 @@ console.log(result.data); // Parsed JSON object
|
|
|
664
673
|
```typescript
|
|
665
674
|
interface ReadJsonInput {
|
|
666
675
|
path: string;
|
|
676
|
+
maxBytes?: number; // The largest count of bytes to load
|
|
667
677
|
}
|
|
668
678
|
```
|
|
669
679
|
|
|
@@ -711,7 +721,7 @@ const { hash, size } = await client.exec(["fs", "hash"], { path: "./archive.tgz"
|
|
|
711
721
|
|
|
712
722
|
#### `fs.temp`
|
|
713
723
|
|
|
714
|
-
The procedure makes a new folder in the temporary folder of the system, and gives its path. With a root, the folder is in the folder `.tmp` of the root. The `prefix` has letters, digits, dots, underscores and hyphens only.
|
|
724
|
+
The procedure makes a new folder in the temporary folder of the system, and gives its path. With a root, the folder is in the folder `.tmp` of the root. The `prefix` has letters, digits, dots, underscores and hyphens only. The prefix is only the start of the name, so a prefix of `..` makes a folder in the same place.
|
|
715
725
|
|
|
716
726
|
#### `fs.watch`
|
|
717
727
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"glob.d.ts","sourceRoot":"","sources":["../../../src/procedures/fs/glob.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;
|
|
1
|
+
{"version":3,"file":"glob.d.ts","sourceRoot":"","sources":["../../../src/procedures/fs/glob.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAKH,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAwC5D;;GAEG;AACH,wBAAsB,IAAI,CAAC,KAAK,EAAE,SAAS,GAAG,OAAO,CAAC,UAAU,CAAC,CAqBhE"}
|
|
@@ -11,45 +11,36 @@
|
|
|
11
11
|
*/
|
|
12
12
|
import { glob as nodeGlob, readdir } from "node:fs/promises";
|
|
13
13
|
import { posix, resolve } from "node:path";
|
|
14
|
-
|
|
15
|
-
// that "*" and "**" match dot entries when `dot` is true.
|
|
16
|
-
const DOT = "\u0001";
|
|
14
|
+
import { globToRegExp } from "@mark1russell7/files/glob";
|
|
17
15
|
/** "a\\b" (Windows) becomes "a/b". */
|
|
18
16
|
function toPosix(path) {
|
|
19
17
|
return path.split("\\").join("/");
|
|
20
18
|
}
|
|
21
|
-
/** Each name of the path that starts with "." starts with DOT instead. */
|
|
22
|
-
function hideDots(path) {
|
|
23
|
-
return path
|
|
24
|
-
.split("/")
|
|
25
|
-
.map((name) => (name.startsWith(".") && name !== "." && name !== ".." ? DOT + name.slice(1) : name))
|
|
26
|
-
.join("/");
|
|
27
|
-
}
|
|
28
19
|
function ignored(path, ignore) {
|
|
29
20
|
return ignore.some((pattern) => posix.matchesGlob(path, pattern));
|
|
30
21
|
}
|
|
31
|
-
/**
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
/** All the matches of `pattern` under `root`, dot entries included. */
|
|
22
|
+
/**
|
|
23
|
+
* All the matches of `pattern` under `root`, dot entries included. The matcher of
|
|
24
|
+
* `@mark1russell7/files` expands the brace groups, and each wildcard matches a leading ".".
|
|
25
|
+
*/
|
|
36
26
|
async function walkWithDots(root, pattern, ignore) {
|
|
37
|
-
const
|
|
38
|
-
const
|
|
27
|
+
const matcher = globToRegExp(pattern, { dot: true });
|
|
28
|
+
const ignorers = ignore.map((entry) => globToRegExp(entry, { dot: true }));
|
|
29
|
+
const isIgnored = (path) => ignorers.some((entry) => entry.test(path));
|
|
39
30
|
const matches = [];
|
|
40
31
|
async function visit(relative) {
|
|
41
32
|
const entries = await readdir(relative ? resolve(root, relative) : root, { withFileTypes: true });
|
|
42
33
|
for (const entry of entries) {
|
|
43
34
|
const path = relative ? `${relative}/${entry.name}` : entry.name;
|
|
44
|
-
const hidden = hideDots(path);
|
|
45
35
|
if (entry.isDirectory()) {
|
|
46
|
-
|
|
36
|
+
// An ignore pattern that matches the folder, alone or with a "/" after it, keeps the walk out of it
|
|
37
|
+
if (isIgnored(path) || isIgnored(`${path}/`))
|
|
47
38
|
continue;
|
|
48
|
-
if (
|
|
39
|
+
if (matcher.test(path))
|
|
49
40
|
matches.push(path);
|
|
50
41
|
await visit(path);
|
|
51
42
|
}
|
|
52
|
-
else if (
|
|
43
|
+
else if (matcher.test(path) && !isIgnored(path)) {
|
|
53
44
|
matches.push(path);
|
|
54
45
|
}
|
|
55
46
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"glob.js","sourceRoot":"","sources":["../../../src/procedures/fs/glob.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,IAAI,IAAI,QAAQ,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"glob.js","sourceRoot":"","sources":["../../../src/procedures/fs/glob.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,IAAI,IAAI,QAAQ,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAGzD,sCAAsC;AACtC,SAAS,OAAO,CAAC,IAAY;IAC3B,OAAO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uF;YACvF,kBAAkB;YAClB,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC;gBAAE,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAClD,CAAC;IACH,CAAC;IAED,QAAQ,CAAC,IAAI,EAAE,CAAC;IAChB,MAAM,OAAO,GAAG,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;IAClF,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC;AAC9B,CAAC"}
|
|
@@ -8,8 +8,8 @@ import { read } from "./read.js";
|
|
|
8
8
|
* Read and parse JSON file
|
|
9
9
|
*/
|
|
10
10
|
export async function readJson(input) {
|
|
11
|
-
const { path } = input;
|
|
12
|
-
const { content, stats } = await read({ path, encoding:
|
|
11
|
+
const { path, maxBytes } = input;
|
|
12
|
+
const { content, stats } = await read({ path, encoding: "utf8", maxBytes });
|
|
13
13
|
const data = JSON.parse(content);
|
|
14
14
|
return { path, data, stats };
|
|
15
15
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json.js","sourceRoot":"","sources":["../../../src/procedures/fs/json.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,QAAQ,CAAC,KAAoB;IACjD,MAAM,EAAE,IAAI,EAAE,GAAG,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"json.js","sourceRoot":"","sources":["../../../src/procedures/fs/json.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,QAAQ,CAAC,KAAoB;IACjD,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAC;IACjC,MAAM,EACJ,OAAO,EACP,KAAK,EACN,GAAG,MAAM,IAAI,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAC;IACrD,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IACjC,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;AAC/B,CAAC"}
|
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* read
|
|
2
|
+
* The procedure `fs.read` reads a file, or a part of a file, as text.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* - `offset` and `length` give a part of the file in bytes. Without them, the procedure reads the
|
|
5
|
+
* whole file.
|
|
6
|
+
* - `maxBytes` is the largest count of bytes that the procedure loads. A larger part gives the
|
|
7
|
+
* error `ERR_FS_FILE_TOO_LARGE`. For a regular file, the error comes before the read. For a pipe
|
|
8
|
+
* or a file of the system with no size, it comes when the count goes over the limit.
|
|
9
|
+
* - Without `maxBytes`, the first read over 16 MiB in the process writes one warning. Version
|
|
10
|
+
* 0.64.0 sets 16 MiB as the default of `maxBytes`.
|
|
5
11
|
*/
|
|
6
12
|
import type { ReadInput, ReadOutput } from "../../types.js";
|
|
7
13
|
/**
|
|
8
|
-
*
|
|
14
|
+
* This function reads a file, or the part that `offset` and `length` give, and decodes it with
|
|
15
|
+
* `encoding`. It loads `maxBytes` at most.
|
|
9
16
|
*/
|
|
10
17
|
export declare function read(input: ReadInput): Promise<ReadOutput>;
|
|
11
18
|
//# sourceMappingURL=read.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"read.d.ts","sourceRoot":"","sources":["../../../src/procedures/fs/read.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"read.d.ts","sourceRoot":"","sources":["../../../src/procedures/fs/read.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAgD5D;;;GAGG;AACH,wBAAsB,IAAI,CAAC,KAAK,EAAE,SAAS,GAAG,OAAO,CAAC,UAAU,CAAC,CAyBhE"}
|
|
@@ -1,21 +1,87 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* read
|
|
2
|
+
* The procedure `fs.read` reads a file, or a part of a file, as text.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* - `offset` and `length` give a part of the file in bytes. Without them, the procedure reads the
|
|
5
|
+
* whole file.
|
|
6
|
+
* - `maxBytes` is the largest count of bytes that the procedure loads. A larger part gives the
|
|
7
|
+
* error `ERR_FS_FILE_TOO_LARGE`. For a regular file, the error comes before the read. For a pipe
|
|
8
|
+
* or a file of the system with no size, it comes when the count goes over the limit.
|
|
9
|
+
* - Without `maxBytes`, the first read over 16 MiB in the process writes one warning. Version
|
|
10
|
+
* 0.64.0 sets 16 MiB as the default of `maxBytes`.
|
|
5
11
|
*/
|
|
6
|
-
import {
|
|
12
|
+
import { open } from "node:fs/promises";
|
|
7
13
|
import { stat } from "./stat.js";
|
|
14
|
+
/** The size in bytes over which a read without `maxBytes` writes a warning: 16 MiB. */
|
|
15
|
+
const WARNING_BYTES = 16 * 1024 * 1024;
|
|
16
|
+
/** The largest piece in bytes of one read of the file. */
|
|
17
|
+
const CHUNK_BYTES = 1024 * 1024;
|
|
18
|
+
let warned = false;
|
|
19
|
+
/** This function gives the error of a part over the limit `maxBytes`. */
|
|
20
|
+
function tooLarge(path, maxBytes) {
|
|
21
|
+
const message = `fs.read: the part of ${JSON.stringify(path)} to read has more than ${String(maxBytes)} bytes, the limit maxBytes. Give a larger maxBytes, or offset and length for a smaller part.`;
|
|
22
|
+
return Object.assign(new RangeError(message), { code: "ERR_FS_FILE_TOO_LARGE" });
|
|
23
|
+
}
|
|
24
|
+
/** This function writes the warning of a large read without `maxBytes`, one time in the process. */
|
|
25
|
+
function warnLargeRead() {
|
|
26
|
+
if (warned)
|
|
27
|
+
return;
|
|
28
|
+
warned = true;
|
|
29
|
+
console.warn(`@procedures/fs 0.64.0 refuses a read over ${String(WARNING_BYTES)} bytes without the input maxBytes. Set maxBytes to read a larger file.`);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* This function reads the part of an open file. With an offset of 0, it reads from the position of
|
|
33
|
+
* the handle, so a pipe also works. It stops at the end of the file, at `length`, or with an error
|
|
34
|
+
* when the count goes over `maxBytes`.
|
|
35
|
+
*/
|
|
36
|
+
async function readPart(handle, path, offset, length, maxBytes) {
|
|
37
|
+
const chunks = [];
|
|
38
|
+
const want = length ?? Number.POSITIVE_INFINITY;
|
|
39
|
+
let total = 0;
|
|
40
|
+
while (total < want) {
|
|
41
|
+
const size = Math.min(CHUNK_BYTES, want - total);
|
|
42
|
+
const chunk = Buffer.allocUnsafe(size);
|
|
43
|
+
const { bytesRead } = await handle.read(chunk, 0, size, offset === 0 ? null : offset + total);
|
|
44
|
+
if (bytesRead === 0)
|
|
45
|
+
break;
|
|
46
|
+
total += bytesRead;
|
|
47
|
+
if (maxBytes !== undefined && total > maxBytes)
|
|
48
|
+
throw tooLarge(path, maxBytes);
|
|
49
|
+
if (maxBytes === undefined && total > WARNING_BYTES)
|
|
50
|
+
warnLargeRead();
|
|
51
|
+
chunks.push(bytesRead === size ? chunk : chunk.subarray(0, bytesRead));
|
|
52
|
+
}
|
|
53
|
+
return Buffer.concat(chunks, total);
|
|
54
|
+
}
|
|
8
55
|
/**
|
|
9
|
-
*
|
|
56
|
+
* This function reads a file, or the part that `offset` and `length` give, and decodes it with
|
|
57
|
+
* `encoding`. It loads `maxBytes` at most.
|
|
10
58
|
*/
|
|
11
59
|
export async function read(input) {
|
|
12
|
-
const { path, encoding } = input;
|
|
13
|
-
|
|
60
|
+
const { path, encoding, offset = 0, length, maxBytes } = input;
|
|
61
|
+
if (!Buffer.isEncoding(encoding)) {
|
|
62
|
+
const message = `fs.read: ${JSON.stringify(encoding)} is not an encoding of Node.js`;
|
|
63
|
+
throw Object.assign(new TypeError(message), { code: "ERR_INVALID_ARG_VALUE" });
|
|
64
|
+
}
|
|
65
|
+
const handle = await open(path, "r");
|
|
66
|
+
let bytes;
|
|
67
|
+
try {
|
|
68
|
+
const info = await handle.stat();
|
|
69
|
+
// The size of a regular file gives the size of the part before the read
|
|
70
|
+
if (maxBytes !== undefined && info.isFile()) {
|
|
71
|
+
const part = Math.max(0, Math.min(info.size - offset, length ?? Number.POSITIVE_INFINITY));
|
|
72
|
+
if (part > maxBytes)
|
|
73
|
+
throw tooLarge(path, maxBytes);
|
|
74
|
+
}
|
|
75
|
+
bytes = await readPart(handle, path, offset, length, maxBytes);
|
|
76
|
+
}
|
|
77
|
+
finally {
|
|
78
|
+
await handle.close();
|
|
79
|
+
}
|
|
14
80
|
const stats = await stat({ path });
|
|
15
81
|
return {
|
|
16
|
-
content,
|
|
82
|
+
content: bytes.toString(encoding),
|
|
17
83
|
path,
|
|
18
|
-
stats
|
|
84
|
+
stats,
|
|
19
85
|
};
|
|
20
86
|
}
|
|
21
87
|
//# sourceMappingURL=read.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"read.js","sourceRoot":"","sources":["../../../src/procedures/fs/read.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"read.js","sourceRoot":"","sources":["../../../src/procedures/fs/read.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,IAAI,EAAmB,MAAM,kBAAkB,CAAC;AAEzD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,uFAAuF;AACvF,MAAM,aAAa,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC;AAEvC,0DAA0D;AAC1D,MAAM,WAAW,GAAG,IAAI,GAAG,IAAI,CAAC;AAEhC,IAAI,MAAM,GAAG,KAAK,CA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,MAAM,IAAI,MAAM,CAAC,iBAAiB,CAAC,CAAC,CAAC;YAC3F,IAAI,IAAI,GAAG,QAAQ;gBAAE,MAAM,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;QACtD,CAAC;QACD,KAAK,GAAG,MAAM,QAAQ,CAAC,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC;IACjE,CAAC;YAAS,CAAC;QACT,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC;IACvB,CAAC;IACD,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;IACnC,OAAO;QACL,OAAO,EAAE,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC;QACjC,IAAI;QACJ,KAAK;KACN,CAAC;AACJ,CAAC"}
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
import type { FsTempInput, FsTempOutput } from "../../types.js";
|
|
9
9
|
/**
|
|
10
10
|
* Make a temporary folder. `base` is the folder that holds it (default: the temporary folder of
|
|
11
|
-
* the system).
|
|
11
|
+
* the system). The prefix is only the start of the name in `base`, also when it is `.` or `..`.
|
|
12
12
|
*/
|
|
13
13
|
export declare function fsTemp(input: FsTempInput, base?: string): Promise<FsTempOutput>;
|
|
14
14
|
//# sourceMappingURL=temp.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"temp.d.ts","sourceRoot":"","sources":["../../../src/procedures/fs/temp.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAKH,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAEhE;;;GAGG;AACH,wBAAsB,MAAM,CAAC,KAAK,EAAE,WAAW,EAAE,IAAI,GAAE,MAAiB,GAAG,OAAO,CAAC,YAAY,CAAC,
|
|
1
|
+
{"version":3,"file":"temp.d.ts","sourceRoot":"","sources":["../../../src/procedures/fs/temp.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAKH,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAEhE;;;GAGG;AACH,wBAAsB,MAAM,CAAC,KAAK,EAAE,WAAW,EAAE,IAAI,GAAE,MAAiB,GAAG,OAAO,CAAC,YAAY,CAAC,CAM/F"}
|
|
@@ -7,14 +7,16 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import { mkdir, mkdtemp } from "node:fs/promises";
|
|
9
9
|
import { tmpdir } from "node:os";
|
|
10
|
-
import {
|
|
10
|
+
import { sep } from "node:path";
|
|
11
11
|
/**
|
|
12
12
|
* Make a temporary folder. `base` is the folder that holds it (default: the temporary folder of
|
|
13
|
-
* the system).
|
|
13
|
+
* the system). The prefix is only the start of the name in `base`, also when it is `.` or `..`.
|
|
14
14
|
*/
|
|
15
15
|
export async function fsTemp(input, base = tmpdir()) {
|
|
16
16
|
await mkdir(base, { recursive: true });
|
|
17
|
-
|
|
17
|
+
// No path arithmetic: `join` reads the prefix `..` as the parent folder of base
|
|
18
|
+
const start = base.endsWith(sep) ? base : base + sep;
|
|
19
|
+
const path = await mkdtemp(start + (input.prefix ?? "procedures-"));
|
|
18
20
|
return { path };
|
|
19
21
|
}
|
|
20
22
|
//# sourceMappingURL=temp.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"temp.js","sourceRoot":"","sources":["../../../src/procedures/fs/temp.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"temp.js","sourceRoot":"","sources":["../../../src/procedures/fs/temp.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAGhC;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,MAAM,CAAC,KAAkB,EAAE,IAAI,GAAW,MAAM,EAAE;IACtE,MAAM,KAAK,CAAC,IAAI,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IACvC,gFAAgF;IAChF,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,GAAG,GAAG,CAAC;IACrD,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC,KAAK,GAAG,CAAC,KAAK,CAAC,MAAM,IAAI,aAAa,CAAC,CAAC,CAAC;IACpE,OAAO,EAAE,IAAI,EAAE,CAAC;AAClB,CAAC"}
|
package/dist/root.d.ts
CHANGED
|
@@ -14,6 +14,9 @@
|
|
|
14
14
|
* lead a write or a `mkdir` out of the root.
|
|
15
15
|
* - A relative target of a symlink starts at the real folder of the link, not at the text of the
|
|
16
16
|
* path. A `..` in the target follows the rule of the system (`link-target.ts`).
|
|
17
|
+
* - On Windows, a network path (`\\host\share\name`) or a device path (`\\.\pipe\name`) of
|
|
18
|
+
* another share than the root is outside. The check refuses it before it opens the path, because
|
|
19
|
+
* an open of a network path connects to its host.
|
|
17
20
|
* - The procedure gets the absolute path, so the paths of the output are absolute.
|
|
18
21
|
*
|
|
19
22
|
* On Windows, the comparison ignores the case of the letters, and `/` and `\` are the same.
|
|
@@ -41,6 +44,12 @@ export interface ResolvedRoot {
|
|
|
41
44
|
folder: string;
|
|
42
45
|
real: string;
|
|
43
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* This function tells if an absolute path is a network or device path of Windows on another share
|
|
49
|
+
* than the root. An open of a network path connects to its host, so the root check refuses such
|
|
50
|
+
* a path before it opens it. On other systems, the result is false.
|
|
51
|
+
*/
|
|
52
|
+
export declare function isOtherShare(root: ResolvedRoot, absolute: string, platform?: NodeJS.Platform): boolean;
|
|
44
53
|
/**
|
|
45
54
|
* This function gives the absolute path and the real path of a root. The root must exist. The
|
|
46
55
|
* error of a missing root names `owner`, for example "the archive procedures".
|
|
@@ -52,7 +61,8 @@ export declare function outsideRoot(procedure: ProcedurePath, message: string):
|
|
|
52
61
|
export declare function isOutsideRoot(error: unknown): boolean;
|
|
53
62
|
/**
|
|
54
63
|
* This function tells if the real path of an absolute path is in the root. It follows each
|
|
55
|
-
* symlink of the path, also a symlink whose target does not exist.
|
|
64
|
+
* symlink of the path, also a symlink whose target does not exist. A network or device path of
|
|
65
|
+
* another share (`isOtherShare`) is outside, and the function does not open it.
|
|
56
66
|
*/
|
|
57
67
|
export declare function realPathIsInside(root: ResolvedRoot, absolute: string): Promise<boolean>;
|
|
58
68
|
/**
|
package/dist/root.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"root.d.ts","sourceRoot":"","sources":["../src/root.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"root.d.ts","sourceRoot":"","sources":["../src/root.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAIH,OAAO,EAAE,eAAe,EAAE,KAAK,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAGzE,OAAO,EAAE,SAAS,EAAE,KAAK,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9D,uEAAuE;AACvE,eAAO,MAAM,YAAY,iBAAiB,CAAC;AAK3C;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAG9D;AAcD;;;;GAIG;AACH,wBAAsB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,SAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAwBzE;AAED,uEAAuE;AACvE,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;CACd;AAgBD;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,GAAE,MAAM,CAAC,QAA2B,GAAG,OAAO,CAIxH;AAED;;;GAGG;AACH,wBAAsB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,SAAwB,GAAG,OAAO,CAAC,YAAY,CAAC,CAUpG;AAED,yDAAyD;AACzD,wBAAgB,WAAW,CAAC,SAAS,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,GAAG,eAAe,CAEtF;AAED,iEAAiE;AACjE,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAErD;AAED;;;;GAIG;AACH,wBAAsB,gBAAgB,CAAC,IAAI,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAG7F;AAED;;;;GAIG;AACH,wBAAsB,MAAM,CAAC,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,aAAa,EAAE,IAAI,GAAE,MAAoB,GAAG,OAAO,CAAC,MAAM,CAAC,CAgBpI"}
|
package/dist/root.js
CHANGED
|
@@ -14,6 +14,9 @@
|
|
|
14
14
|
* lead a write or a `mkdir` out of the root.
|
|
15
15
|
* - A relative target of a symlink starts at the real folder of the link, not at the text of the
|
|
16
16
|
* path. A `..` in the target follows the rule of the system (`link-target.ts`).
|
|
17
|
+
* - On Windows, a network path (`\\host\share\name`) or a device path (`\\.\pipe\name`) of
|
|
18
|
+
* another share than the root is outside. The check refuses it before it opens the path, because
|
|
19
|
+
* an open of a network path connects to its host.
|
|
17
20
|
* - The procedure gets the absolute path, so the paths of the output are absolute.
|
|
18
21
|
*
|
|
19
22
|
* On Windows, the comparison ignores the case of the letters, and `/` and `\` are the same.
|
|
@@ -22,7 +25,7 @@
|
|
|
22
25
|
* operation reads the links that the check read.
|
|
23
26
|
*/
|
|
24
27
|
import { readlink, realpath } from "node:fs/promises";
|
|
25
|
-
import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
28
|
+
import { basename, dirname, isAbsolute, join, relative, resolve, sep, win32 } from "node:path";
|
|
26
29
|
import { InvocationError } from "@procedures/client";
|
|
27
30
|
import { isMissing, linkDestination } from "./link-target.js";
|
|
28
31
|
export { holdRoots } from "./root-hold.js";
|
|
@@ -84,6 +87,31 @@ export async function realPathOf(path, links = 0) {
|
|
|
84
87
|
current = parent;
|
|
85
88
|
}
|
|
86
89
|
}
|
|
90
|
+
/**
|
|
91
|
+
* This function gives the share of a network or device path of Windows, in lower case. For
|
|
92
|
+
* `\\host\share\x` and `\\?\UNC\host\share\x` it gives `host\share`. For `\\.\pipe\x` it gives
|
|
93
|
+
* `.\pipe`. For each other path it gives undefined.
|
|
94
|
+
*/
|
|
95
|
+
function windowsShare(path) {
|
|
96
|
+
const normal = win32.normalize(path);
|
|
97
|
+
if (!normal.startsWith("\\\\"))
|
|
98
|
+
return undefined;
|
|
99
|
+
const parts = normal.slice(2).split("\\");
|
|
100
|
+
const device = parts[0] === "?" || parts[0] === ".";
|
|
101
|
+
const start = device && parts[1]?.toLowerCase() === "unc" ? 2 : 0;
|
|
102
|
+
return parts.slice(start, start + 2).join("\\").toLowerCase();
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* This function tells if an absolute path is a network or device path of Windows on another share
|
|
106
|
+
* than the root. An open of a network path connects to its host, so the root check refuses such
|
|
107
|
+
* a path before it opens it. On other systems, the result is false.
|
|
108
|
+
*/
|
|
109
|
+
export function isOtherShare(root, absolute, platform = process.platform) {
|
|
110
|
+
if (platform !== "win32")
|
|
111
|
+
return false;
|
|
112
|
+
const share = windowsShare(absolute);
|
|
113
|
+
return share !== undefined && share !== windowsShare(root.folder) && share !== windowsShare(root.real);
|
|
114
|
+
}
|
|
87
115
|
/**
|
|
88
116
|
* This function gives the absolute path and the real path of a root. The root must exist. The
|
|
89
117
|
* error of a missing root names `owner`, for example "the archive procedures".
|
|
@@ -111,9 +139,12 @@ export function isOutsideRoot(error) {
|
|
|
111
139
|
}
|
|
112
140
|
/**
|
|
113
141
|
* This function tells if the real path of an absolute path is in the root. It follows each
|
|
114
|
-
* symlink of the path, also a symlink whose target does not exist.
|
|
142
|
+
* symlink of the path, also a symlink whose target does not exist. A network or device path of
|
|
143
|
+
* another share (`isOtherShare`) is outside, and the function does not open it.
|
|
115
144
|
*/
|
|
116
145
|
export async function realPathIsInside(root, absolute) {
|
|
146
|
+
if (isOtherShare(root, absolute))
|
|
147
|
+
return false;
|
|
117
148
|
return isInside(root.real, await realPathOf(absolute));
|
|
118
149
|
}
|
|
119
150
|
/**
|
|
@@ -123,6 +154,10 @@ export async function realPathIsInside(root, absolute) {
|
|
|
123
154
|
*/
|
|
124
155
|
export async function inRoot(root, path, procedure, base = root.folder) {
|
|
125
156
|
const absolute = resolve(base, path);
|
|
157
|
+
// The real path of a network path opens a connection to its host, so this check comes first
|
|
158
|
+
if (isOtherShare(root, absolute)) {
|
|
159
|
+
throw outsideRoot(procedure, `the path ${JSON.stringify(path)} is a network or device path outside the root ${root.folder}`);
|
|
160
|
+
}
|
|
126
161
|
const real = await realPathOf(absolute);
|
|
127
162
|
// A path counts as inside by its given form or by its real form. On Windows, the two forms of a
|
|
128
163
|
// folder can differ by more than the links: a short 8.3 name (RUNNER~1) has a long real name.
|
package/dist/root.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"root.js","sourceRoot":"","sources":["../src/root.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"root.js","sourceRoot":"","sources":["../src/root.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAAE,QAAQ,EAA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,CAAC,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,CAAC;QACrG,MAAM,WAAW,CAAC,SAAS,EAAE,YAAY,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,wBAAwB,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;IACtG,CAAC;IACD,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,CAAC;QAC/B,MAAM,WAAW,CAAC,SAAS,EAAE,YAAY,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,0BAA0B,IAAI,CAAC,MAAM,oBAAoB,CAAC,CAAC;IAC1H,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -6,6 +6,9 @@ import * as z from "zod";
|
|
|
6
6
|
export declare const ReadInputSchema: z.ZodObject<{
|
|
7
7
|
path: z.ZodString;
|
|
8
8
|
encoding: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
9
|
+
offset: z.ZodOptional<z.ZodNumber>;
|
|
10
|
+
length: z.ZodOptional<z.ZodNumber>;
|
|
11
|
+
maxBytes: z.ZodOptional<z.ZodNumber>;
|
|
9
12
|
}>;
|
|
10
13
|
export type ReadInput = z.infer<typeof ReadInputSchema>;
|
|
11
14
|
export interface ReadOutput {
|
|
@@ -166,6 +169,7 @@ export interface GlobOutput {
|
|
|
166
169
|
}
|
|
167
170
|
export declare const ReadJsonInputSchema: z.ZodObject<{
|
|
168
171
|
path: z.ZodString;
|
|
172
|
+
maxBytes: z.ZodOptional<z.ZodNumber>;
|
|
169
173
|
}>;
|
|
170
174
|
export type ReadJsonInput = z.infer<typeof ReadJsonInputSchema>;
|
|
171
175
|
export interface ReadJsonOutput {
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AAMzB,eAAO,MAAM,eAAe,EAAE,CAAC,CAAC,SAAS,CAAC;IACxC,IAAI,EAAE,CAAC,CAAC,SAAS,CAAC;IAClB,QAAQ,EAAE,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AAMzB,eAAO,MAAM,eAAe,EAAE,CAAC,CAAC,SAAS,CAAC;IACxC,IAAI,EAAE,CAAC,CAAC,SAAS,CAAC;IAClB,QAAQ,EAAE,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC;IACnD,MAAM,EAAE,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;IACnC,MAAM,EAAE,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;IACnC,QAAQ,EAAE,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;CACtC,CAWC,CAAC;AAEH,MAAM,MAAM,SAAS,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,eAAe,CAAC,CAAC;AAExD,MAAM,WAAW,UAAU;IACzB,mBAAmB;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,gBAAgB;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,yBA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11
|
/** File encoding (default: utf8) */
|
|
12
12
|
encoding: z.string().optional().default("utf8").describe("File encoding (default: utf8)"),
|
|
13
|
+
/** The first byte of the part to read. The default is 0. A part of a text can cut a character of more than one byte. */
|
|
14
|
+
offset: z.number().int().min(0).optional().describe("The first byte of the part to read (default 0)"),
|
|
15
|
+
/** The count of bytes of the part to read. Without it, the part goes to the end of the file. */
|
|
16
|
+
length: z.number().int().min(0).optional().describe("The count of bytes to read (default: to the end of the file)"),
|
|
17
|
+
/** The largest count of bytes that the read loads. A larger part gives the error `ERR_FS_FILE_TOO_LARGE`. */
|
|
18
|
+
maxBytes: z.number().int().min(0).optional().describe("The largest count of bytes to load. A larger part fails with ERR_FS_FILE_TOO_LARGE"),
|
|
13
19
|
});
|
|
14
20
|
// =============================================================================
|
|
15
21
|
// write Types - Write content to file
|
|
@@ -127,6 +133,8 @@ export const GlobInputSchema = z.object({
|
|
|
127
133
|
export const ReadJsonInputSchema = z.object({
|
|
128
134
|
/** Path to JSON file */
|
|
129
135
|
path: z.string().describe("Path to JSON file"),
|
|
136
|
+
/** The largest count of bytes that the read loads. A larger file gives the error `ERR_FS_FILE_TOO_LARGE`. */
|
|
137
|
+
maxBytes: z.number().int().min(0).optional().describe("The largest count of bytes to load. A larger file fails with ERR_FS_FILE_TOO_LARGE"),
|
|
130
138
|
});
|
|
131
139
|
// =============================================================================
|
|
132
140
|
// Output schemas (roadmap 2.1)
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AAEzB,gFAAgF;AAChF,kCAAkC;AAClC,gFAAgF;AAEhF,MAAM,CAAC,MAAM,eAAe,
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,KAAK,CAAC,MAA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IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,4BAA4B,CAAC;CACxD,CAAC,CAAC;AAiBH,MAAM,CAAC,MAAM,kBAAkB,GAA4B,CAAC,CAAC,MAAM,CAAC;IAClE,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,6BAA6B,CAAC;IACxD,SAAS,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,oCAAoC,CAAC;CACjF,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,mBAAmB,GAA6B,CAAC,CAAC,WAAW,CAAC;IACzE,KAAK,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,yEAAyE,CAAC;IACvH,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,wEAAwE,CAAC;CACnH,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package",
|
|
3
3
|
"name": "@procedures/fs",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.61.0",
|
|
5
5
|
"description": "File system procedures: read, write, copy, move, glob, exists, mkdir and JSON read and write, callable in process, over RPC or from Claude through MCP.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"filesystem",
|
|
@@ -76,7 +76,8 @@
|
|
|
76
76
|
},
|
|
77
77
|
"dependencies": {
|
|
78
78
|
"@mark1russell7/collections": "^0.11.1",
|
|
79
|
-
"@
|
|
79
|
+
"@mark1russell7/files": "^0.0.3",
|
|
80
|
+
"@procedures/client": "0.61.0",
|
|
80
81
|
"zod": "^4.6.5"
|
|
81
82
|
},
|
|
82
83
|
"devDependencies": {
|
|
@@ -12,50 +12,38 @@
|
|
|
12
12
|
|
|
13
13
|
import { glob as nodeGlob, readdir } from "node:fs/promises";
|
|
14
14
|
import { posix, resolve } from "node:path";
|
|
15
|
+
import { globToRegExp } from "@mark1russell7/files/glob";
|
|
15
16
|
import type { GlobInput, GlobOutput } from "../../types.js";
|
|
16
17
|
|
|
17
|
-
// A character that a file name cannot hold. It takes the place of a leading "." of a name, so
|
|
18
|
-
// that "*" and "**" match dot entries when `dot` is true.
|
|
19
|
-
const DOT = "\u0001";
|
|
20
|
-
|
|
21
18
|
/** "a\\b" (Windows) becomes "a/b". */
|
|
22
19
|
function toPosix(path: string): string {
|
|
23
20
|
return path.split("\\").join("/");
|
|
24
21
|
}
|
|
25
22
|
|
|
26
|
-
/** Each name of the path that starts with "." starts with DOT instead. */
|
|
27
|
-
function hideDots(path: string): string {
|
|
28
|
-
return path
|
|
29
|
-
.split("/")
|
|
30
|
-
.map((name) => (name.startsWith(".") && name !== "." && name !== ".." ? DOT + name.slice(1) : name))
|
|
31
|
-
.join("/");
|
|
32
|
-
}
|
|
33
|
-
|
|
34
23
|
function ignored(path: string, ignore: readonly string[]): boolean {
|
|
35
24
|
return ignore.some((pattern) => posix.matchesGlob(path, pattern));
|
|
36
25
|
}
|
|
37
26
|
|
|
38
|
-
/**
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
/** All the matches of `pattern` under `root`, dot entries included. */
|
|
27
|
+
/**
|
|
28
|
+
* All the matches of `pattern` under `root`, dot entries included. The matcher of
|
|
29
|
+
* `@mark1russell7/files` expands the brace groups, and each wildcard matches a leading ".".
|
|
30
|
+
*/
|
|
44
31
|
async function walkWithDots(root: string, pattern: string, ignore: readonly string[]): Promise<string[]> {
|
|
45
|
-
const
|
|
46
|
-
const
|
|
32
|
+
const matcher = globToRegExp(pattern, { dot: true });
|
|
33
|
+
const ignorers = ignore.map((entry) => globToRegExp(entry, { dot: true }));
|
|
34
|
+
const isIgnored = (path: string): boolean => ignorers.some((entry) => entry.test(path));
|
|
47
35
|
const matches: string[] = [];
|
|
48
36
|
|
|
49
37
|
async function visit(relative: string): Promise<void> {
|
|
50
38
|
const entries = await readdir(relative ? resolve(root, relative) : root, { withFileTypes: true });
|
|
51
39
|
for (const entry of entries) {
|
|
52
40
|
const path = relative ? `${relative}/${entry.name}` : entry.name;
|
|
53
|
-
const hidden = hideDots(path);
|
|
54
41
|
if (entry.isDirectory()) {
|
|
55
|
-
|
|
56
|
-
if (
|
|
42
|
+
// An ignore pattern that matches the folder, alone or with a "/" after it, keeps the walk out of it
|
|
43
|
+
if (isIgnored(path) || isIgnored(`${path}/`)) continue;
|
|
44
|
+
if (matcher.test(path)) matches.push(path);
|
|
57
45
|
await visit(path);
|
|
58
|
-
} else if (
|
|
46
|
+
} else if (matcher.test(path) && !isIgnored(path)) {
|
|
59
47
|
matches.push(path);
|
|
60
48
|
}
|
|
61
49
|
}
|
|
@@ -11,11 +11,11 @@ import { read } from "./read.js";
|
|
|
11
11
|
* Read and parse JSON file
|
|
12
12
|
*/
|
|
13
13
|
export async function readJson(input: ReadJsonInput): Promise<ReadJsonOutput> {
|
|
14
|
-
const { path } = input;
|
|
14
|
+
const { path, maxBytes } = input;
|
|
15
15
|
const {
|
|
16
16
|
content,
|
|
17
17
|
stats
|
|
18
|
-
} = await read({path, encoding
|
|
18
|
+
} = await read({ path, encoding: "utf8", maxBytes });
|
|
19
19
|
const data = JSON.parse(content);
|
|
20
20
|
return { path, data, stats };
|
|
21
21
|
}
|
|
@@ -1,23 +1,91 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* read
|
|
2
|
+
* The procedure `fs.read` reads a file, or a part of a file, as text.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* - `offset` and `length` give a part of the file in bytes. Without them, the procedure reads the
|
|
5
|
+
* whole file.
|
|
6
|
+
* - `maxBytes` is the largest count of bytes that the procedure loads. A larger part gives the
|
|
7
|
+
* error `ERR_FS_FILE_TOO_LARGE`. For a regular file, the error comes before the read. For a pipe
|
|
8
|
+
* or a file of the system with no size, it comes when the count goes over the limit.
|
|
9
|
+
* - Without `maxBytes`, the first read over 16 MiB in the process writes one warning. Version
|
|
10
|
+
* 0.64.0 sets 16 MiB as the default of `maxBytes`.
|
|
5
11
|
*/
|
|
6
12
|
|
|
7
|
-
import {
|
|
13
|
+
import { open, type FileHandle } from "node:fs/promises";
|
|
8
14
|
import type { ReadInput, ReadOutput } from "../../types.js";
|
|
9
15
|
import { stat } from "./stat.js";
|
|
10
16
|
|
|
17
|
+
/** The size in bytes over which a read without `maxBytes` writes a warning: 16 MiB. */
|
|
18
|
+
const WARNING_BYTES = 16 * 1024 * 1024;
|
|
19
|
+
|
|
20
|
+
/** The largest piece in bytes of one read of the file. */
|
|
21
|
+
const CHUNK_BYTES = 1024 * 1024;
|
|
22
|
+
|
|
23
|
+
let warned = false;
|
|
24
|
+
|
|
25
|
+
/** This function gives the error of a part over the limit `maxBytes`. */
|
|
26
|
+
function tooLarge(path: string, maxBytes: number): RangeError {
|
|
27
|
+
const message = `fs.read: the part of ${JSON.stringify(path)} to read has more than ${String(maxBytes)} bytes, the limit maxBytes. Give a larger maxBytes, or offset and length for a smaller part.`;
|
|
28
|
+
return Object.assign(new RangeError(message), { code: "ERR_FS_FILE_TOO_LARGE" });
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** This function writes the warning of a large read without `maxBytes`, one time in the process. */
|
|
32
|
+
function warnLargeRead(): void {
|
|
33
|
+
if (warned) return;
|
|
34
|
+
warned = true;
|
|
35
|
+
console.warn(
|
|
36
|
+
`@procedures/fs 0.64.0 refuses a read over ${String(WARNING_BYTES)} bytes without the input maxBytes. Set maxBytes to read a larger file.`,
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* This function reads the part of an open file. With an offset of 0, it reads from the position of
|
|
42
|
+
* the handle, so a pipe also works. It stops at the end of the file, at `length`, or with an error
|
|
43
|
+
* when the count goes over `maxBytes`.
|
|
44
|
+
*/
|
|
45
|
+
async function readPart(handle: FileHandle, path: string, offset: number, length: number | undefined, maxBytes: number | undefined): Promise<Buffer> {
|
|
46
|
+
const chunks: Buffer[] = [];
|
|
47
|
+
const want = length ?? Number.POSITIVE_INFINITY;
|
|
48
|
+
let total = 0;
|
|
49
|
+
while (total < want) {
|
|
50
|
+
const size = Math.min(CHUNK_BYTES, want - total);
|
|
51
|
+
const chunk = Buffer.allocUnsafe(size);
|
|
52
|
+
const { bytesRead } = await handle.read(chunk, 0, size, offset === 0 ? null : offset + total);
|
|
53
|
+
if (bytesRead === 0) break;
|
|
54
|
+
total += bytesRead;
|
|
55
|
+
if (maxBytes !== undefined && total > maxBytes) throw tooLarge(path, maxBytes);
|
|
56
|
+
if (maxBytes === undefined && total > WARNING_BYTES) warnLargeRead();
|
|
57
|
+
chunks.push(bytesRead === size ? chunk : chunk.subarray(0, bytesRead));
|
|
58
|
+
}
|
|
59
|
+
return Buffer.concat(chunks, total);
|
|
60
|
+
}
|
|
61
|
+
|
|
11
62
|
/**
|
|
12
|
-
*
|
|
63
|
+
* This function reads a file, or the part that `offset` and `length` give, and decodes it with
|
|
64
|
+
* `encoding`. It loads `maxBytes` at most.
|
|
13
65
|
*/
|
|
14
66
|
export async function read(input: ReadInput): Promise<ReadOutput> {
|
|
15
|
-
const { path, encoding } = input;
|
|
16
|
-
|
|
17
|
-
|
|
67
|
+
const { path, encoding, offset = 0, length, maxBytes } = input;
|
|
68
|
+
if (!Buffer.isEncoding(encoding)) {
|
|
69
|
+
const message = `fs.read: ${JSON.stringify(encoding)} is not an encoding of Node.js`;
|
|
70
|
+
throw Object.assign(new TypeError(message), { code: "ERR_INVALID_ARG_VALUE" });
|
|
71
|
+
}
|
|
72
|
+
const handle = await open(path, "r");
|
|
73
|
+
let bytes: Buffer;
|
|
74
|
+
try {
|
|
75
|
+
const info = await handle.stat();
|
|
76
|
+
// The size of a regular file gives the size of the part before the read
|
|
77
|
+
if (maxBytes !== undefined && info.isFile()) {
|
|
78
|
+
const part = Math.max(0, Math.min(info.size - offset, length ?? Number.POSITIVE_INFINITY));
|
|
79
|
+
if (part > maxBytes) throw tooLarge(path, maxBytes);
|
|
80
|
+
}
|
|
81
|
+
bytes = await readPart(handle, path, offset, length, maxBytes);
|
|
82
|
+
} finally {
|
|
83
|
+
await handle.close();
|
|
84
|
+
}
|
|
85
|
+
const stats = await stat({ path });
|
|
18
86
|
return {
|
|
19
|
-
content,
|
|
87
|
+
content: bytes.toString(encoding),
|
|
20
88
|
path,
|
|
21
|
-
stats
|
|
89
|
+
stats,
|
|
22
90
|
};
|
|
23
91
|
}
|
|
@@ -8,15 +8,17 @@
|
|
|
8
8
|
|
|
9
9
|
import { mkdir, mkdtemp } from "node:fs/promises";
|
|
10
10
|
import { tmpdir } from "node:os";
|
|
11
|
-
import {
|
|
11
|
+
import { sep } from "node:path";
|
|
12
12
|
import type { FsTempInput, FsTempOutput } from "../../types.js";
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* Make a temporary folder. `base` is the folder that holds it (default: the temporary folder of
|
|
16
|
-
* the system).
|
|
16
|
+
* the system). The prefix is only the start of the name in `base`, also when it is `.` or `..`.
|
|
17
17
|
*/
|
|
18
18
|
export async function fsTemp(input: FsTempInput, base: string = tmpdir()): Promise<FsTempOutput> {
|
|
19
19
|
await mkdir(base, { recursive: true });
|
|
20
|
-
|
|
20
|
+
// No path arithmetic: `join` reads the prefix `..` as the parent folder of base
|
|
21
|
+
const start = base.endsWith(sep) ? base : base + sep;
|
|
22
|
+
const path = await mkdtemp(start + (input.prefix ?? "procedures-"));
|
|
21
23
|
return { path };
|
|
22
24
|
}
|
package/src/root.ts
CHANGED
|
@@ -14,6 +14,9 @@
|
|
|
14
14
|
* lead a write or a `mkdir` out of the root.
|
|
15
15
|
* - A relative target of a symlink starts at the real folder of the link, not at the text of the
|
|
16
16
|
* path. A `..` in the target follows the rule of the system (`link-target.ts`).
|
|
17
|
+
* - On Windows, a network path (`\\host\share\name`) or a device path (`\\.\pipe\name`) of
|
|
18
|
+
* another share than the root is outside. The check refuses it before it opens the path, because
|
|
19
|
+
* an open of a network path connects to its host.
|
|
17
20
|
* - The procedure gets the absolute path, so the paths of the output are absolute.
|
|
18
21
|
*
|
|
19
22
|
* On Windows, the comparison ignores the case of the letters, and `/` and `\` are the same.
|
|
@@ -23,7 +26,7 @@
|
|
|
23
26
|
*/
|
|
24
27
|
|
|
25
28
|
import { readlink, realpath } from "node:fs/promises";
|
|
26
|
-
import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
29
|
+
import { basename, dirname, isAbsolute, join, relative, resolve, sep, win32 } from "node:path";
|
|
27
30
|
import { InvocationError, type ProcedurePath } from "@procedures/client";
|
|
28
31
|
import { isMissing, linkDestination } from "./link-target.js";
|
|
29
32
|
|
|
@@ -93,6 +96,31 @@ export interface ResolvedRoot {
|
|
|
93
96
|
real: string;
|
|
94
97
|
}
|
|
95
98
|
|
|
99
|
+
/**
|
|
100
|
+
* This function gives the share of a network or device path of Windows, in lower case. For
|
|
101
|
+
* `\\host\share\x` and `\\?\UNC\host\share\x` it gives `host\share`. For `\\.\pipe\x` it gives
|
|
102
|
+
* `.\pipe`. For each other path it gives undefined.
|
|
103
|
+
*/
|
|
104
|
+
function windowsShare(path: string): string | undefined {
|
|
105
|
+
const normal = win32.normalize(path);
|
|
106
|
+
if (!normal.startsWith("\\\\")) return undefined;
|
|
107
|
+
const parts = normal.slice(2).split("\\");
|
|
108
|
+
const device = parts[0] === "?" || parts[0] === ".";
|
|
109
|
+
const start = device && parts[1]?.toLowerCase() === "unc" ? 2 : 0;
|
|
110
|
+
return parts.slice(start, start + 2).join("\\").toLowerCase();
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* This function tells if an absolute path is a network or device path of Windows on another share
|
|
115
|
+
* than the root. An open of a network path connects to its host, so the root check refuses such
|
|
116
|
+
* a path before it opens it. On other systems, the result is false.
|
|
117
|
+
*/
|
|
118
|
+
export function isOtherShare(root: ResolvedRoot, absolute: string, platform: NodeJS.Platform = process.platform): boolean {
|
|
119
|
+
if (platform !== "win32") return false;
|
|
120
|
+
const share = windowsShare(absolute);
|
|
121
|
+
return share !== undefined && share !== windowsShare(root.folder) && share !== windowsShare(root.real);
|
|
122
|
+
}
|
|
123
|
+
|
|
96
124
|
/**
|
|
97
125
|
* This function gives the absolute path and the real path of a root. The root must exist. The
|
|
98
126
|
* error of a missing root names `owner`, for example "the archive procedures".
|
|
@@ -121,9 +149,11 @@ export function isOutsideRoot(error: unknown): boolean {
|
|
|
121
149
|
|
|
122
150
|
/**
|
|
123
151
|
* This function tells if the real path of an absolute path is in the root. It follows each
|
|
124
|
-
* symlink of the path, also a symlink whose target does not exist.
|
|
152
|
+
* symlink of the path, also a symlink whose target does not exist. A network or device path of
|
|
153
|
+
* another share (`isOtherShare`) is outside, and the function does not open it.
|
|
125
154
|
*/
|
|
126
155
|
export async function realPathIsInside(root: ResolvedRoot, absolute: string): Promise<boolean> {
|
|
156
|
+
if (isOtherShare(root, absolute)) return false;
|
|
127
157
|
return isInside(root.real, await realPathOf(absolute));
|
|
128
158
|
}
|
|
129
159
|
|
|
@@ -134,6 +164,10 @@ export async function realPathIsInside(root: ResolvedRoot, absolute: string): Pr
|
|
|
134
164
|
*/
|
|
135
165
|
export async function inRoot(root: ResolvedRoot, path: string, procedure: ProcedurePath, base: string = root.folder): Promise<string> {
|
|
136
166
|
const absolute = resolve(base, path);
|
|
167
|
+
// The real path of a network path opens a connection to its host, so this check comes first
|
|
168
|
+
if (isOtherShare(root, absolute)) {
|
|
169
|
+
throw outsideRoot(procedure, `the path ${JSON.stringify(path)} is a network or device path outside the root ${root.folder}`);
|
|
170
|
+
}
|
|
137
171
|
const real = await realPathOf(absolute);
|
|
138
172
|
// A path counts as inside by its given form or by its real form. On Windows, the two forms of a
|
|
139
173
|
// folder can differ by more than the links: a short 8.3 name (RUNNER~1) has a long real name.
|
package/src/types.ts
CHANGED
|
@@ -12,11 +12,20 @@ import * as z from "zod";
|
|
|
12
12
|
export const ReadInputSchema: z.ZodObject<{
|
|
13
13
|
path: z.ZodString;
|
|
14
14
|
encoding: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
15
|
+
offset: z.ZodOptional<z.ZodNumber>;
|
|
16
|
+
length: z.ZodOptional<z.ZodNumber>;
|
|
17
|
+
maxBytes: z.ZodOptional<z.ZodNumber>;
|
|
15
18
|
}> = z.object({
|
|
16
19
|
/** Path to file to read */
|
|
17
20
|
path: z.string().describe("Path to file to read"),
|
|
18
21
|
/** File encoding (default: utf8) */
|
|
19
22
|
encoding: z.string().optional().default("utf8").describe("File encoding (default: utf8)"),
|
|
23
|
+
/** The first byte of the part to read. The default is 0. A part of a text can cut a character of more than one byte. */
|
|
24
|
+
offset: z.number().int().min(0).optional().describe("The first byte of the part to read (default 0)"),
|
|
25
|
+
/** The count of bytes of the part to read. Without it, the part goes to the end of the file. */
|
|
26
|
+
length: z.number().int().min(0).optional().describe("The count of bytes to read (default: to the end of the file)"),
|
|
27
|
+
/** The largest count of bytes that the read loads. A larger part gives the error `ERR_FS_FILE_TOO_LARGE`. */
|
|
28
|
+
maxBytes: z.number().int().min(0).optional().describe("The largest count of bytes to load. A larger part fails with ERR_FS_FILE_TOO_LARGE"),
|
|
20
29
|
});
|
|
21
30
|
|
|
22
31
|
export type ReadInput = z.infer<typeof ReadInputSchema>;
|
|
@@ -313,9 +322,12 @@ export interface GlobOutput {
|
|
|
313
322
|
|
|
314
323
|
export const ReadJsonInputSchema: z.ZodObject<{
|
|
315
324
|
path: z.ZodString;
|
|
325
|
+
maxBytes: z.ZodOptional<z.ZodNumber>;
|
|
316
326
|
}> = z.object({
|
|
317
327
|
/** Path to JSON file */
|
|
318
328
|
path: z.string().describe("Path to JSON file"),
|
|
329
|
+
/** The largest count of bytes that the read loads. A larger file gives the error `ERR_FS_FILE_TOO_LARGE`. */
|
|
330
|
+
maxBytes: z.number().int().min(0).optional().describe("The largest count of bytes to load. A larger file fails with ERR_FS_FILE_TOO_LARGE"),
|
|
319
331
|
});
|
|
320
332
|
|
|
321
333
|
export type ReadJsonInput = z.infer<typeof ReadJsonInputSchema>;
|