redzip 4.3.0 → 4.5.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 +10 -0
- package/lib/local/date.js +27 -0
- package/lib/local/index.js +8 -55
- package/lib/local/read-stat.js +23 -0
- package/package.json +1 -1
package/ChangeLog
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
2026.02.26, v4.5.0
|
|
2
|
+
|
|
3
|
+
feature:
|
|
4
|
+
- e187d34 redzip: local: move out date
|
|
5
|
+
|
|
6
|
+
2026.02.26, v4.4.0
|
|
7
|
+
|
|
8
|
+
feature:
|
|
9
|
+
- 47b3069 redzip: local: write: keep mtime of parent directory when creating directory (coderaiser/cloudcmd#457)
|
|
10
|
+
|
|
1
11
|
2026.02.25, v4.3.0
|
|
2
12
|
|
|
3
13
|
feature:
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import {dirname} from 'node:path';
|
|
2
|
+
import {mkdir, utimes} from 'node:fs/promises';
|
|
3
|
+
import {tryToCatch} from 'try-to-catch';
|
|
4
|
+
import {readStat} from './read-stat.js';
|
|
5
|
+
|
|
6
|
+
const maybeSetDate = async (path, date) => {
|
|
7
|
+
if (!date)
|
|
8
|
+
return;
|
|
9
|
+
|
|
10
|
+
await tryToCatch(utimes, path, date, date);
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export const keepParentDate = (fn) => async (outerPath, innerPath, readStream, options = {}) => {
|
|
14
|
+
const {date} = options;
|
|
15
|
+
|
|
16
|
+
const dirPath = dirname(outerPath);
|
|
17
|
+
const {date: dirDate} = await readStat(dirPath);
|
|
18
|
+
|
|
19
|
+
await mkdir(dirPath, {
|
|
20
|
+
recursive: true,
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
await fn(outerPath, innerPath, readStream, options);
|
|
24
|
+
|
|
25
|
+
await maybeSetDate(outerPath, date);
|
|
26
|
+
await tryToCatch(utimes, dirPath, dirDate, dirDate);
|
|
27
|
+
};
|
package/lib/local/index.js
CHANGED
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
join,
|
|
3
|
-
basename,
|
|
4
|
-
dirname,
|
|
5
|
-
} from 'node:path';
|
|
1
|
+
import {join} from 'node:path';
|
|
6
2
|
import {
|
|
7
3
|
createReadStream as _createReadStream,
|
|
8
4
|
createWriteStream,
|
|
@@ -15,48 +11,31 @@ import {
|
|
|
15
11
|
unlink as _unlink,
|
|
16
12
|
lstat,
|
|
17
13
|
opendir,
|
|
18
|
-
utimes,
|
|
19
14
|
} from 'node:fs/promises';
|
|
20
15
|
import readify from 'readify';
|
|
21
16
|
import trammel from 'trammel';
|
|
22
17
|
import {tryToCatch} from 'try-to-catch';
|
|
23
18
|
import pipe from 'pipe-io';
|
|
19
|
+
import {keepParentDate} from './date.js';
|
|
20
|
+
|
|
21
|
+
export {readStat} from './read-stat.js';
|
|
24
22
|
|
|
25
23
|
const notDir = (e) => e?.code === 'ENOTDIR';
|
|
26
24
|
const winNotDir = (e) => e?.code === 'ENOENT';
|
|
27
25
|
|
|
28
26
|
const {assign} = Object;
|
|
29
27
|
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
return;
|
|
33
|
-
|
|
34
|
-
await tryToCatch(utimes, path, date, date);
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
export const write = async (outerPath, innerPath, readStream, options = {}) => {
|
|
38
|
-
const {
|
|
39
|
-
unzip,
|
|
40
|
-
mode,
|
|
41
|
-
date,
|
|
42
|
-
} = options;
|
|
28
|
+
export const write = keepParentDate(async (outerPath, innerPath, readStream, options) => {
|
|
29
|
+
const {unzip, mode} = options;
|
|
43
30
|
|
|
44
31
|
if (!readStream) {
|
|
45
32
|
await mkdir(outerPath, {
|
|
46
|
-
recursive: true,
|
|
47
33
|
mode,
|
|
34
|
+
recursive: true,
|
|
48
35
|
});
|
|
49
|
-
await maybeSetDate(outerPath, date);
|
|
50
|
-
|
|
51
36
|
return;
|
|
52
37
|
}
|
|
53
38
|
|
|
54
|
-
const dirPath = dirname(outerPath);
|
|
55
|
-
|
|
56
|
-
await mkdir(dirPath, {
|
|
57
|
-
recursive: true,
|
|
58
|
-
});
|
|
59
|
-
|
|
60
39
|
const writeStream = createWriteStream(outerPath, {
|
|
61
40
|
mode,
|
|
62
41
|
});
|
|
@@ -64,13 +43,8 @@ export const write = async (outerPath, innerPath, readStream, options = {}) => {
|
|
|
64
43
|
if (unzip)
|
|
65
44
|
return await pipe([readStream, createGunzip(), writeStream]);
|
|
66
45
|
|
|
67
|
-
const {date: dirDate} = await readStat(dirPath);
|
|
68
|
-
|
|
69
46
|
await pipe([readStream, writeStream]);
|
|
70
|
-
|
|
71
|
-
await maybeSetDate(outerPath, date);
|
|
72
|
-
await maybeSetDate(dirPath, dirDate);
|
|
73
|
-
};
|
|
47
|
+
});
|
|
74
48
|
|
|
75
49
|
export const readSize = async (outerPath, innerPath, options) => {
|
|
76
50
|
return await trammel(outerPath, options);
|
|
@@ -151,27 +125,6 @@ async function listAll(outerPath) {
|
|
|
151
125
|
return names;
|
|
152
126
|
}
|
|
153
127
|
|
|
154
|
-
export const readStat = async (outerPath) => {
|
|
155
|
-
const statResult = await lstat(outerPath);
|
|
156
|
-
const {
|
|
157
|
-
mtime,
|
|
158
|
-
mode,
|
|
159
|
-
uid,
|
|
160
|
-
} = statResult;
|
|
161
|
-
|
|
162
|
-
const type = statResult.isDirectory() ? 'dir' : 'file';
|
|
163
|
-
const size = statResult.isDirectory() ? 0 : statResult.size;
|
|
164
|
-
|
|
165
|
-
return {
|
|
166
|
-
type,
|
|
167
|
-
name: basename(outerPath),
|
|
168
|
-
size,
|
|
169
|
-
date: mtime,
|
|
170
|
-
owner: uid,
|
|
171
|
-
mode,
|
|
172
|
-
};
|
|
173
|
-
};
|
|
174
|
-
|
|
175
128
|
async function* walk(dir) {
|
|
176
129
|
for await (const dirent of await opendir(dir)) {
|
|
177
130
|
const {name} = dirent;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import {lstat} from 'node:fs/promises';
|
|
2
|
+
import {basename} from 'node:path';
|
|
3
|
+
|
|
4
|
+
export const readStat = async (outerPath) => {
|
|
5
|
+
const statResult = await lstat(outerPath);
|
|
6
|
+
const {
|
|
7
|
+
mtime,
|
|
8
|
+
mode,
|
|
9
|
+
uid,
|
|
10
|
+
} = statResult;
|
|
11
|
+
|
|
12
|
+
const type = statResult.isDirectory() ? 'dir' : 'file';
|
|
13
|
+
const size = statResult.isDirectory() ? 0 : statResult.size;
|
|
14
|
+
|
|
15
|
+
return {
|
|
16
|
+
type,
|
|
17
|
+
name: basename(outerPath),
|
|
18
|
+
size,
|
|
19
|
+
date: mtime,
|
|
20
|
+
owner: uid,
|
|
21
|
+
mode,
|
|
22
|
+
};
|
|
23
|
+
};
|