redzip 4.4.0 → 4.5.1
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 +26 -0
- package/lib/local/index.js +8 -56
- package/lib/local/read-stat.js +23 -0
- package/package.json +1 -1
package/ChangeLog
CHANGED
|
@@ -0,0 +1,26 @@
|
|
|
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
|
+
const dirPath = dirname(outerPath);
|
|
16
|
+
|
|
17
|
+
await mkdir(dirPath, {
|
|
18
|
+
recursive: true,
|
|
19
|
+
});
|
|
20
|
+
const {date: dirDate} = await readStat(dirPath);
|
|
21
|
+
|
|
22
|
+
await fn(outerPath, innerPath, readStream, options);
|
|
23
|
+
|
|
24
|
+
await maybeSetDate(outerPath, date);
|
|
25
|
+
await tryToCatch(utimes, dirPath, dirDate, dirDate);
|
|
26
|
+
};
|
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,51 +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;
|
|
43
|
-
|
|
44
|
-
const dirPath = dirname(outerPath);
|
|
45
|
-
const {date: dirDate} = await readStat(dirPath);
|
|
28
|
+
export const write = keepParentDate(async (outerPath, innerPath, readStream, options) => {
|
|
29
|
+
const {unzip, mode} = options;
|
|
46
30
|
|
|
47
31
|
if (!readStream) {
|
|
48
32
|
await mkdir(outerPath, {
|
|
49
|
-
recursive: true,
|
|
50
33
|
mode,
|
|
34
|
+
recursive: true,
|
|
51
35
|
});
|
|
52
|
-
|
|
53
|
-
await maybeSetDate(outerPath, date);
|
|
54
|
-
await maybeSetDate(dirPath, dirDate);
|
|
55
|
-
|
|
56
36
|
return;
|
|
57
37
|
}
|
|
58
38
|
|
|
59
|
-
await mkdir(dirPath, {
|
|
60
|
-
recursive: true,
|
|
61
|
-
});
|
|
62
|
-
|
|
63
39
|
const writeStream = createWriteStream(outerPath, {
|
|
64
40
|
mode,
|
|
65
41
|
});
|
|
@@ -68,10 +44,7 @@ export const write = async (outerPath, innerPath, readStream, options = {}) => {
|
|
|
68
44
|
return await pipe([readStream, createGunzip(), writeStream]);
|
|
69
45
|
|
|
70
46
|
await pipe([readStream, writeStream]);
|
|
71
|
-
|
|
72
|
-
await maybeSetDate(outerPath, date);
|
|
73
|
-
await maybeSetDate(dirPath, dirDate);
|
|
74
|
-
};
|
|
47
|
+
});
|
|
75
48
|
|
|
76
49
|
export const readSize = async (outerPath, innerPath, options) => {
|
|
77
50
|
return await trammel(outerPath, options);
|
|
@@ -152,27 +125,6 @@ async function listAll(outerPath) {
|
|
|
152
125
|
return names;
|
|
153
126
|
}
|
|
154
127
|
|
|
155
|
-
export const readStat = async (outerPath) => {
|
|
156
|
-
const statResult = await lstat(outerPath);
|
|
157
|
-
const {
|
|
158
|
-
mtime,
|
|
159
|
-
mode,
|
|
160
|
-
uid,
|
|
161
|
-
} = statResult;
|
|
162
|
-
|
|
163
|
-
const type = statResult.isDirectory() ? 'dir' : 'file';
|
|
164
|
-
const size = statResult.isDirectory() ? 0 : statResult.size;
|
|
165
|
-
|
|
166
|
-
return {
|
|
167
|
-
type,
|
|
168
|
-
name: basename(outerPath),
|
|
169
|
-
size,
|
|
170
|
-
date: mtime,
|
|
171
|
-
owner: uid,
|
|
172
|
-
mode,
|
|
173
|
-
};
|
|
174
|
-
};
|
|
175
|
-
|
|
176
128
|
async function* walk(dir) {
|
|
177
129
|
for await (const dirent of await opendir(dir)) {
|
|
178
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
|
+
};
|