@zukhruf/fs 0.8.17 → 0.8.19
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/dist/atomic-write.d.ts +2 -2
- package/dist/atomic-write.d.ts.map +1 -1
- package/dist/atomic-write.js +6 -3
- package/dist/atomic-write.js.map +1 -1
- package/dist/durable-write.js +4 -1
- package/dist/durable-write.js.map +1 -1
- package/dist/patiently.d.ts.map +1 -1
- package/dist/patiently.js +8 -2
- package/dist/patiently.js.map +1 -1
- package/package.json +4 -4
package/dist/atomic-write.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { Clock } from '@zukhruf/async';
|
|
2
2
|
/**
|
|
3
3
|
* Replaces `path` in one step, so readers see the old or the new content, never a partial write.
|
|
4
|
-
* `mode`
|
|
5
|
-
* so the file never has another mode at the path.
|
|
4
|
+
* The draft gets `mode` before the rename, and the rename keeps the draft's
|
|
5
|
+
* mode, so the file never has another mode at the path.
|
|
6
6
|
*/
|
|
7
7
|
export declare function atomicWrite(path: string, content: string | Uint8Array, { clock, mode }: {
|
|
8
8
|
clock: Clock;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"atomic-write.d.ts","sourceRoot":"","sources":["../src/atomic-write.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAK5C;;;;GAIG;AACH,wBAAsB,WAAW,CAC/B,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,GAAG,UAAU,EAC5B,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE;IAAE,KAAK,EAAE,KAAK,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,
|
|
1
|
+
{"version":3,"file":"atomic-write.d.ts","sourceRoot":"","sources":["../src/atomic-write.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAK5C;;;;GAIG;AACH,wBAAsB,WAAW,CAC/B,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,GAAG,UAAU,EAC5B,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE;IAAE,KAAK,EAAE,KAAK,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,iBAajD"}
|
package/dist/atomic-write.js
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
|
-
import { rm, writeFile } from 'node:fs/promises';
|
|
1
|
+
import { chmod, rm, writeFile } from 'node:fs/promises';
|
|
2
2
|
import { draftOf } from "./draft.js";
|
|
3
3
|
import { replaceFile } from "./replace-file.js";
|
|
4
4
|
/**
|
|
5
5
|
* Replaces `path` in one step, so readers see the old or the new content, never a partial write.
|
|
6
|
-
* `mode`
|
|
7
|
-
* so the file never has another mode at the path.
|
|
6
|
+
* The draft gets `mode` before the rename, and the rename keeps the draft's
|
|
7
|
+
* mode, so the file never has another mode at the path.
|
|
8
8
|
*/
|
|
9
9
|
export async function atomicWrite(path, content, { clock, mode }) {
|
|
10
10
|
const draft = draftOf(path);
|
|
11
11
|
try {
|
|
12
12
|
await writeFile(draft, content, { mode });
|
|
13
|
+
// The umask masks the mode of a new file; a chmod does not, as in write-file-atomic 5.0.1 (lib/index.js:134).
|
|
14
|
+
if (mode !== undefined)
|
|
15
|
+
await chmod(draft, mode);
|
|
13
16
|
await replaceFile(draft, path, clock);
|
|
14
17
|
}
|
|
15
18
|
catch (error) {
|
package/dist/atomic-write.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"atomic-write.js","sourceRoot":"","sources":["../src/atomic-write.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"atomic-write.js","sourceRoot":"","sources":["../src/atomic-write.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAIxD,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,IAAY,EACZ,OAA4B,EAC5B,EAAE,KAAK,EAAE,IAAI,EAAmC;IAEhD,MAAM,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5B,IAAI,CAAC;QACH,MAAM,SAAS,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC;QAC1C,8GAA8G;QAC9G,IAAI,IAAI,KAAK,SAAS;YAAE,MAAM,KAAK,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;QACjD,MAAM,WAAW,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;IACxC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,+EAA+E;QAC/E,MAAM,EAAE,CAAC,KAAK,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;QACjC,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC"}
|
package/dist/durable-write.js
CHANGED
|
@@ -11,7 +11,7 @@ import { replaceFile } from "./replace-file.js";
|
|
|
11
11
|
export async function durableWrite(path, content, { clock, mode }) {
|
|
12
12
|
const draft = draftOf(path);
|
|
13
13
|
try {
|
|
14
|
-
// The rename keeps the draft's mode, so `mode`
|
|
14
|
+
// The rename keeps the draft's mode, so the draft gets `mode` before it.
|
|
15
15
|
await writeSynced(draft, content, mode);
|
|
16
16
|
await replaceFile(draft, path, clock);
|
|
17
17
|
}
|
|
@@ -24,6 +24,9 @@ export async function durableWrite(path, content, { clock, mode }) {
|
|
|
24
24
|
}
|
|
25
25
|
async function writeSynced(path, content, mode) {
|
|
26
26
|
await using handle = await open(path, 'wx', mode);
|
|
27
|
+
// The umask masks the mode of a new file; a chmod does not, as in write-file-atomic 5.0.1 (lib/index.js:134).
|
|
28
|
+
if (mode !== undefined)
|
|
29
|
+
await handle.chmod(mode);
|
|
27
30
|
await handle.writeFile(content);
|
|
28
31
|
await handle.sync();
|
|
29
32
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"durable-write.js","sourceRoot":"","sources":["../src/durable-write.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAIpC,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,IAAY,EACZ,OAA4B,EAC5B,EAAE,KAAK,EAAE,IAAI,EAAmC;IAEhD,MAAM,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5B,IAAI,CAAC;QACH,
|
|
1
|
+
{"version":3,"file":"durable-write.js","sourceRoot":"","sources":["../src/durable-write.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAIpC,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,IAAY,EACZ,OAA4B,EAC5B,EAAE,KAAK,EAAE,IAAI,EAAmC;IAEhD,MAAM,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5B,IAAI,CAAC;QACH,y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":3,"file":"patiently.d.ts","sourceRoot":"","sources":["../src/patiently.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"patiently.d.ts","sourceRoot":"","sources":["../src/patiently.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,KAAK,KAAK,EAAS,MAAM,gBAAgB,CAAC;AA2B5D;;;;GAIG;AACH,wBAAsB,SAAS,CAAC,CAAC,EAC/B,SAAS,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EAC3B,EAAE,KAAK,EAAE,EAAE;IAAE,KAAK,EAAE,KAAK,CAAA;CAAE,GAC1B,OAAO,CAAC,CAAC,CAAC,CAiBZ"}
|
package/dist/patiently.js
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
|
-
import { delay } from '@zukhruf/async';
|
|
1
|
+
import { Backoff, delay } from '@zukhruf/async';
|
|
2
2
|
import { isErrno } from "./errno.js";
|
|
3
3
|
/** How long to retry a file operation that Windows refuses for a moment. */
|
|
4
4
|
const WINDOWS_PATIENCE = 1000;
|
|
5
|
+
const WINDOWS_BACKOFF = new Backoff({
|
|
6
|
+
initial: 5,
|
|
7
|
+
multiplier: 2,
|
|
8
|
+
max: 100,
|
|
9
|
+
jitter: { kind: 'none' },
|
|
10
|
+
});
|
|
5
11
|
/**
|
|
6
12
|
* Windows refuses a file for a moment while another program holds it open
|
|
7
13
|
* with no sharing, as a virus scanner can, or while a delete of it is in
|
|
@@ -27,7 +33,7 @@ export async function patiently(operation, { clock }) {
|
|
|
27
33
|
if (!isRefusedForNow(error) ||
|
|
28
34
|
clock.performance.now() - started > WINDOWS_PATIENCE)
|
|
29
35
|
throw error;
|
|
30
|
-
await delay(
|
|
36
|
+
await delay(WINDOWS_BACKOFF.duration(attempt), {
|
|
31
37
|
clock,
|
|
32
38
|
signal: undefined,
|
|
33
39
|
});
|
package/dist/patiently.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"patiently.js","sourceRoot":"","sources":["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,eAAe,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE;gBAC7C,KAAK;gBACL,MAAM,EAAE,SAAS;aAClB,CAAC,CAAC;QACL,CAAC;IACH,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zukhruf/fs",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.19",
|
|
4
4
|
"description": "File writes a reader never sees half done, a file lock the kernel frees when its holder dies, and a file stamp that tells that a file changed, as git does. Retries Windows' short refusals. Names a file after any key.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -50,10 +50,10 @@
|
|
|
50
50
|
"access": "public"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"@zukhruf/async": "^0.8.
|
|
54
|
-
"@zukhruf/sqlite-open": "^0.8.
|
|
53
|
+
"@zukhruf/async": "^0.8.19",
|
|
54
|
+
"@zukhruf/sqlite-open": "^0.8.19"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
|
-
"@zukhruf/testing": "^0.8.
|
|
57
|
+
"@zukhruf/testing": "^0.8.19"
|
|
58
58
|
}
|
|
59
59
|
}
|