redzip 2.2.0 → 3.0.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 +19 -0
- package/README.md +22 -18
- package/lib/local/index.js +11 -15
- package/lib/redfs.js +11 -3
- package/lib/vfs/list/index.js +0 -1
- package/lib/vfs/read/index.js +2 -0
- package/lib/vfs/read-size/index.js +0 -1
- package/lib/vfs/read-stat/index.js +0 -1
- package/lib/vfs/remove/index.js +0 -1
- package/lib/vfs/write/index.js +0 -1
- package/lib/zip/index.js +0 -1
- package/lib/zip/list/index.js +5 -7
- package/lib/zip/read/index.js +3 -3
- package/lib/zip/read-size/index.js +2 -5
- package/lib/zip/read-stat/index.js +0 -1
- package/lib/zip/remove/index.js +0 -1
- package/lib/zip/write/index.js +3 -10
- package/package.json +14 -14
package/ChangeLog
CHANGED
|
@@ -1,3 +1,22 @@
|
|
|
1
|
+
2023.08.09, v3.0.0
|
|
2
|
+
|
|
3
|
+
feature:
|
|
4
|
+
- b4fcada redzip: drop support of node < 16
|
|
5
|
+
- 258f2a8 redzip: simplify
|
|
6
|
+
- d668395 package: eslint-plugin-n v16.0.1
|
|
7
|
+
- 453ad3a package: supertape v8.4.1
|
|
8
|
+
- fce75b0 package: madrun v9.3.1
|
|
9
|
+
- 3a49c1d package: eslint-plugin-putout v19.0.3
|
|
10
|
+
- d8804d9 package: putout v31.0.4
|
|
11
|
+
- 92e7da5 package: memfs v4.2.1
|
|
12
|
+
- e2020f7 package: nodemon v3.0.1
|
|
13
|
+
- 0a831e6 package: c8 v8.0.1
|
|
14
|
+
- 9f4fa92 package: @iocmd/wait v2.1.0
|
|
15
|
+
- d65c1af package: totalist v3.0.1
|
|
16
|
+
- b439588 (package) eslint-plugin-putout v12.7.1
|
|
17
|
+
- 80e4037 (package) eslint v8.4.1
|
|
18
|
+
- b59351a (package) putout v22.8.2
|
|
19
|
+
|
|
1
20
|
2021.09.20, v2.2.0
|
|
2
21
|
|
|
3
22
|
fix:
|
package/README.md
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
# Redzip [![License][LicenseIMGURL]][LicenseURL] [![NPM version][NPMIMGURL]][NPMURL] [![
|
|
1
|
+
# Redzip [![License][LicenseIMGURL]][LicenseURL] [![NPM version][NPMIMGURL]][NPMURL] [![Build Status][BuildStatusIMGURL]][BuildStatusURL] [![Coverage Status][CoverageIMGURL]][CoverageURL]
|
|
2
2
|
|
|
3
3
|
[NPMIMGURL]: https://img.shields.io/npm/v/redzip.svg?style=flat
|
|
4
4
|
[BuildStatusURL]: https://github.com/coderaiser/redzip/actions
|
|
5
5
|
[BuildStatusIMGURL]: https://github.com/coderaiser/redzip/workflows/CI/badge.svg
|
|
6
|
-
[DependencyStatusIMGURL]: https://img.shields.io/david/coderaiser/redzip.svg?style=flat
|
|
7
6
|
[LicenseIMGURL]: https://img.shields.io/badge/license-MIT-317BF9.svg?style=flat
|
|
8
7
|
[NPMURL]: https://npmjs.org/package/redzip "npm"
|
|
9
8
|
[BuildStatusURL]: https://travis-ci.org/coderaiser/redzip "Build Status"
|
|
10
|
-
[DependencyStatusURL]: https://david-dm.org/coderaiser/redzip "Dependency Status"
|
|
11
9
|
[LicenseURL]: https://tldrlegal.com/license/mit-license "MIT License"
|
|
12
10
|
[CoverageURL]: https://coveralls.io/github/coderaiser/redzip?branch=master
|
|
13
11
|
[CoverageIMGURL]: https://coveralls.io/repos/coderaiser/redzip/badge.svg?branch=master&service=github
|
|
@@ -43,7 +41,11 @@ const path = '/home/coderaiser/hello.zip/hello.txt';
|
|
|
43
41
|
|
|
44
42
|
const redzip = require('redzip');
|
|
45
43
|
|
|
46
|
-
const dirStream = await redzip.read(dirPath, {
|
|
44
|
+
const dirStream = await redzip.read(dirPath, {
|
|
45
|
+
type,
|
|
46
|
+
sort,
|
|
47
|
+
order,
|
|
48
|
+
});
|
|
47
49
|
console.log(dirStream.type);
|
|
48
50
|
// outputs
|
|
49
51
|
'directory';
|
|
@@ -55,7 +57,7 @@ console.log(dirStream.contentLength);
|
|
|
55
57
|
dirStream.pipe(process.stdout);
|
|
56
58
|
// outputs
|
|
57
59
|
({
|
|
58
|
-
path:
|
|
60
|
+
path: '/',
|
|
59
61
|
files: [{
|
|
60
62
|
name: 'redzip.js',
|
|
61
63
|
size: 4735,
|
|
@@ -118,8 +120,7 @@ fileStream.pipe(process.stdout);
|
|
|
118
120
|
// outputs
|
|
119
121
|
'10kb';
|
|
120
122
|
|
|
121
|
-
fileStream.contentLength
|
|
122
|
-
// 4
|
|
123
|
+
fileStream.contentLength;// 4
|
|
123
124
|
```
|
|
124
125
|
|
|
125
126
|
### readStat(path[, options])
|
|
@@ -128,19 +129,22 @@ fileStream.contentLength;
|
|
|
128
129
|
|
|
129
130
|
```js
|
|
130
131
|
const stat = readStat('/hello/world.zip/readme.md');
|
|
132
|
+
|
|
131
133
|
// returns
|
|
132
134
|
({
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
135
|
+
date: '2021-01-18T22:00:00.000Z',
|
|
136
|
+
mode: 1_107_099_648,
|
|
137
|
+
name: 'readme.md',
|
|
138
|
+
owner: 0,
|
|
139
|
+
size: 0,
|
|
140
|
+
type: 'file',
|
|
139
141
|
});
|
|
140
142
|
```
|
|
141
143
|
|
|
142
144
|
### write(path[, data], options)
|
|
143
145
|
|
|
146
|
+
When you need to save `string`, or `Buffer` use [Readable.from](https://nodejs.org/dist/latest-v17.x/docs/api/stream.html#streamreadablefromiterable-options).
|
|
147
|
+
|
|
144
148
|
- **path** - `string`
|
|
145
149
|
- **data** - `stream`
|
|
146
150
|
- **options** - `object` can contain:
|
|
@@ -161,6 +165,7 @@ await write(dirPath);
|
|
|
161
165
|
|
|
162
166
|
const path = '/home/coderaiser/hello.zip/hello.txt';
|
|
163
167
|
const writeStream = await write(path, Readable.from('hello'));
|
|
168
|
+
|
|
164
169
|
await pullout(writeStream);
|
|
165
170
|
// returns
|
|
166
171
|
'save: ok("hello")';
|
|
@@ -171,7 +176,9 @@ await pullout(await read(path));
|
|
|
171
176
|
|
|
172
177
|
import {createGzip} from 'zlib';
|
|
173
178
|
|
|
174
|
-
const zipStream = Readable
|
|
179
|
+
const zipStream = Readable
|
|
180
|
+
.from('hello')
|
|
181
|
+
.pipe(createGzip());
|
|
175
182
|
await write(path, zipStream, {
|
|
176
183
|
unzip: true,
|
|
177
184
|
});
|
|
@@ -181,12 +188,9 @@ await pullout(readStream);
|
|
|
181
188
|
'hello';
|
|
182
189
|
```
|
|
183
190
|
|
|
184
|
-
### remove(path
|
|
191
|
+
### remove(path)
|
|
185
192
|
|
|
186
193
|
- **path** - `string`
|
|
187
|
-
- **data** - `stream`
|
|
188
|
-
- **options** - `object` can contain:
|
|
189
|
-
- `unzip` - unzip file content before writing
|
|
190
194
|
|
|
191
195
|
#### Example
|
|
192
196
|
|
package/lib/local/index.js
CHANGED
|
@@ -5,12 +5,14 @@ const {
|
|
|
5
5
|
basename,
|
|
6
6
|
dirname,
|
|
7
7
|
} = require('path');
|
|
8
|
+
|
|
8
9
|
const {
|
|
9
10
|
createReadStream,
|
|
10
11
|
createWriteStream,
|
|
11
12
|
} = require('fs');
|
|
12
13
|
|
|
13
14
|
const {createGunzip} = require('zlib');
|
|
15
|
+
|
|
14
16
|
const {
|
|
15
17
|
realpath,
|
|
16
18
|
mkdir,
|
|
@@ -50,16 +52,9 @@ module.exports.write = async (outerPath, innerPath, readStream, options = {}) =>
|
|
|
50
52
|
});
|
|
51
53
|
|
|
52
54
|
if (unzip)
|
|
53
|
-
return await pipe([
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
writeStream,
|
|
57
|
-
]);
|
|
58
|
-
|
|
59
|
-
await pipe([
|
|
60
|
-
readStream,
|
|
61
|
-
writeStream,
|
|
62
|
-
]);
|
|
55
|
+
return await pipe([readStream, createGunzip(), writeStream]);
|
|
56
|
+
|
|
57
|
+
await pipe([readStream, writeStream]);
|
|
63
58
|
};
|
|
64
59
|
|
|
65
60
|
module.exports.readSize = async (outerPath, innerPath, options) => {
|
|
@@ -79,7 +74,11 @@ module.exports.remove = async (outerPath) => {
|
|
|
79
74
|
throw error;
|
|
80
75
|
};
|
|
81
76
|
|
|
82
|
-
module.exports.read = async (path, innerPath, {
|
|
77
|
+
module.exports.read = async (path, innerPath, {
|
|
78
|
+
type,
|
|
79
|
+
sort,
|
|
80
|
+
order,
|
|
81
|
+
} = {}) => {
|
|
83
82
|
const [error, result] = await tryToCatch(readify, path, {
|
|
84
83
|
type,
|
|
85
84
|
sort,
|
|
@@ -111,9 +110,7 @@ module.exports.list = async (outerPath) => {
|
|
|
111
110
|
const [error, names] = await tryToCatch(list, outerPath);
|
|
112
111
|
|
|
113
112
|
if (notDir(error))
|
|
114
|
-
return [
|
|
115
|
-
outerPath,
|
|
116
|
-
];
|
|
113
|
+
return [outerPath];
|
|
117
114
|
|
|
118
115
|
if (error)
|
|
119
116
|
throw error;
|
|
@@ -164,4 +161,3 @@ async function* walk(dir) {
|
|
|
164
161
|
yield path;
|
|
165
162
|
}
|
|
166
163
|
}
|
|
167
|
-
|
package/lib/redfs.js
CHANGED
|
@@ -9,14 +9,23 @@ module.exports = (path) => {
|
|
|
9
9
|
const [outerPath, innerPath] = split(path);
|
|
10
10
|
|
|
11
11
|
if (!innerPath)
|
|
12
|
-
return [
|
|
12
|
+
return [
|
|
13
|
+
local,
|
|
14
|
+
path,
|
|
15
|
+
'',
|
|
16
|
+
];
|
|
13
17
|
|
|
14
|
-
return [
|
|
18
|
+
return [
|
|
19
|
+
zip,
|
|
20
|
+
outerPath,
|
|
21
|
+
innerPath,
|
|
22
|
+
];
|
|
15
23
|
};
|
|
16
24
|
|
|
17
25
|
function split(path) {
|
|
18
26
|
const replaced = path.replace(`.zip${sep}`, `*${sep}`);
|
|
19
27
|
let [outer, inner = ''] = replaced.split('*');
|
|
28
|
+
|
|
20
29
|
inner = inner.replace(/\\/g, '/');
|
|
21
30
|
|
|
22
31
|
return [
|
|
@@ -24,4 +33,3 @@ function split(path) {
|
|
|
24
33
|
inner || '',
|
|
25
34
|
];
|
|
26
35
|
}
|
|
27
|
-
|
package/lib/vfs/list/index.js
CHANGED
package/lib/vfs/read/index.js
CHANGED
|
@@ -27,6 +27,7 @@ module.exports = async (path, options = {}) => {
|
|
|
27
27
|
});
|
|
28
28
|
|
|
29
29
|
const [vfs, outerPath, innerPath] = redfs(path);
|
|
30
|
+
|
|
30
31
|
const content = await vfs.read(outerPath, innerPath, {
|
|
31
32
|
type,
|
|
32
33
|
sort,
|
|
@@ -39,6 +40,7 @@ module.exports = async (path, options = {}) => {
|
|
|
39
40
|
return content;
|
|
40
41
|
|
|
41
42
|
const files = content;
|
|
43
|
+
|
|
42
44
|
const str = stringify({
|
|
43
45
|
path: currentPath,
|
|
44
46
|
files,
|
package/lib/vfs/remove/index.js
CHANGED
package/lib/vfs/write/index.js
CHANGED
package/lib/zip/index.js
CHANGED
package/lib/zip/list/index.js
CHANGED
|
@@ -3,20 +3,19 @@
|
|
|
3
3
|
const {join} = require('path');
|
|
4
4
|
const readzip = require('readzip');
|
|
5
5
|
|
|
6
|
-
const addSlash = (a) => a
|
|
6
|
+
const addSlash = (a) => a.at(-1) === '/' ? a : `${a}/`;
|
|
7
7
|
|
|
8
8
|
module.exports = async (outerPath, innerPath) => {
|
|
9
9
|
const paths = [];
|
|
10
10
|
const rootDir = addSlash(innerPath);
|
|
11
11
|
|
|
12
12
|
for await (const path of readzip(outerPath)) {
|
|
13
|
-
const {
|
|
14
|
-
directory,
|
|
15
|
-
filePath,
|
|
16
|
-
} = path;
|
|
13
|
+
const {directory, filePath} = path;
|
|
17
14
|
|
|
18
15
|
if (path.isFile(innerPath))
|
|
19
|
-
return [
|
|
16
|
+
return [
|
|
17
|
+
join(outerPath, filePath),
|
|
18
|
+
];
|
|
20
19
|
|
|
21
20
|
if (!directory.includes(rootDir))
|
|
22
21
|
continue;
|
|
@@ -26,4 +25,3 @@ module.exports = async (outerPath, innerPath) => {
|
|
|
26
25
|
|
|
27
26
|
return paths;
|
|
28
27
|
};
|
|
29
|
-
|
package/lib/zip/read/index.js
CHANGED
|
@@ -7,7 +7,7 @@ const formatify = require('@cloudcmd/formatify');
|
|
|
7
7
|
const readzip = require('readzip');
|
|
8
8
|
|
|
9
9
|
const ifRaw = (type, fn, a) => type === 'raw' ? a : fn(a);
|
|
10
|
-
const isEndSlash = (a) => a
|
|
10
|
+
const isEndSlash = (a) => a.at(-1) === sep;
|
|
11
11
|
const addSlash = (a) => isEndSlash(a) ? a : `${a}${sep}`;
|
|
12
12
|
|
|
13
13
|
const {assign} = Object;
|
|
@@ -25,6 +25,7 @@ module.exports = async (outerPath, innerPath, options = {}) => {
|
|
|
25
25
|
let stream;
|
|
26
26
|
let found = inner === '/';
|
|
27
27
|
const owner = 'root';
|
|
28
|
+
|
|
28
29
|
for await (const path of readzip(outerPath)) {
|
|
29
30
|
const {
|
|
30
31
|
name,
|
|
@@ -72,9 +73,8 @@ module.exports = async (outerPath, innerPath, options = {}) => {
|
|
|
72
73
|
return stream;
|
|
73
74
|
|
|
74
75
|
const sorted = sortify({sort, order}, names);
|
|
75
|
-
const files = ifRaw(type, formatify, sorted);
|
|
76
76
|
|
|
77
|
-
return
|
|
77
|
+
return ifRaw(type, formatify, sorted);
|
|
78
78
|
};
|
|
79
79
|
|
|
80
80
|
function createError(path) {
|
|
@@ -7,11 +7,9 @@ module.exports = async (outerPath, innerPath, options = {}) => {
|
|
|
7
7
|
const {type} = options;
|
|
8
8
|
|
|
9
9
|
let sum = 0;
|
|
10
|
+
|
|
10
11
|
for await (const path of readzip(outerPath)) {
|
|
11
|
-
const {
|
|
12
|
-
size,
|
|
13
|
-
filePath,
|
|
14
|
-
} = path;
|
|
12
|
+
const {size, filePath} = path;
|
|
15
13
|
|
|
16
14
|
if (path.isFile() && !filePath.indexOf(innerPath))
|
|
17
15
|
sum += size;
|
|
@@ -22,4 +20,3 @@ module.exports = async (outerPath, innerPath, options = {}) => {
|
|
|
22
20
|
|
|
23
21
|
return format.size(sum);
|
|
24
22
|
};
|
|
25
|
-
|
package/lib/zip/remove/index.js
CHANGED
package/lib/zip/write/index.js
CHANGED
|
@@ -5,10 +5,8 @@ const {promisify} = require('util');
|
|
|
5
5
|
const {join, dirname} = require('path').posix;
|
|
6
6
|
const {createWriteStream} = require('fs');
|
|
7
7
|
const {createGunzip} = require('zlib');
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
unlink,
|
|
11
|
-
} = require('fs/promises');
|
|
8
|
+
|
|
9
|
+
const {rename, unlink} = require('fs/promises');
|
|
12
10
|
|
|
13
11
|
const yazl = require('yazl');
|
|
14
12
|
const pipe = require('pipe-io');
|
|
@@ -40,7 +38,6 @@ module.exports = async (outerPath, innerPath, stream, options = {}) => {
|
|
|
40
38
|
update(outerPath, innerPath, readStream, zipfile, {
|
|
41
39
|
remove,
|
|
42
40
|
}),
|
|
43
|
-
|
|
44
41
|
replace(outerPath, tmpName, outputStream),
|
|
45
42
|
]);
|
|
46
43
|
|
|
@@ -101,10 +98,7 @@ async function update(outerPath, innerPath, stream, zipfile, {remove}) {
|
|
|
101
98
|
async function replace(outerPath, name, stream) {
|
|
102
99
|
const writeStream = createWriteStream(name);
|
|
103
100
|
|
|
104
|
-
await pipe([
|
|
105
|
-
stream,
|
|
106
|
-
writeStream,
|
|
107
|
-
]);
|
|
101
|
+
await pipe([stream, writeStream]);
|
|
108
102
|
|
|
109
103
|
const [error] = await tryToCatch(rename, name, outerPath);
|
|
110
104
|
|
|
@@ -113,4 +107,3 @@ async function replace(outerPath, name, stream) {
|
|
|
113
107
|
throw error;
|
|
114
108
|
}
|
|
115
109
|
}
|
|
116
|
-
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "redzip",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
|
+
"type": "commonjs",
|
|
4
5
|
"main": "lib/redzip.js",
|
|
5
6
|
"description": "work with files inside archives like with regular files",
|
|
6
7
|
"author": "",
|
|
@@ -30,7 +31,7 @@
|
|
|
30
31
|
"pipe-io": "^4.0.1",
|
|
31
32
|
"readify": "^9.0.0",
|
|
32
33
|
"readzip": "^1.0.0",
|
|
33
|
-
"totalist": "^
|
|
34
|
+
"totalist": "^3.0.1",
|
|
34
35
|
"trammel": "^5.0.0",
|
|
35
36
|
"try-to-catch": "^3.0.0",
|
|
36
37
|
"wraptile": "^3.0.0",
|
|
@@ -40,20 +41,19 @@
|
|
|
40
41
|
"devDependencies": {
|
|
41
42
|
"@babel/core": "^7.12.10",
|
|
42
43
|
"@babel/eslint-parser": "^7.12.1",
|
|
43
|
-
"@
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"eslint": "^
|
|
47
|
-
"eslint-plugin-
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"memfs": "^3.2.0",
|
|
44
|
+
"@iocmd/wait": "^2.1.0",
|
|
45
|
+
"c8": "^8.0.1",
|
|
46
|
+
"eslint": "^8.4.1",
|
|
47
|
+
"eslint-plugin-n": "^16.0.1",
|
|
48
|
+
"eslint-plugin-putout": "^19.0.3",
|
|
49
|
+
"madrun": "^9.3.1",
|
|
50
|
+
"memfs": "^4.2.1",
|
|
51
51
|
"mock-fs": "^5.0.0",
|
|
52
52
|
"mock-require": "^3.0.1",
|
|
53
|
-
"nodemon": "^
|
|
53
|
+
"nodemon": "^3.0.1",
|
|
54
54
|
"pullout": "^4.0.0",
|
|
55
|
-
"putout": "^
|
|
56
|
-
"supertape": "^
|
|
55
|
+
"putout": "^31.0.4",
|
|
56
|
+
"supertape": "^8.4.1"
|
|
57
57
|
},
|
|
58
58
|
"keywords": [
|
|
59
59
|
"directory",
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
"zip"
|
|
66
66
|
],
|
|
67
67
|
"engines": {
|
|
68
|
-
"node": ">=
|
|
68
|
+
"node": ">=16"
|
|
69
69
|
},
|
|
70
70
|
"license": "MIT"
|
|
71
71
|
}
|