redzip 2.1.4 → 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 CHANGED
@@ -1,3 +1,34 @@
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
+
20
+ 2021.09.20, v2.2.0
21
+
22
+ fix:
23
+ - (redzip) can't remove files in windows (#1)
24
+
25
+ feature:
26
+ - (package) eslint v8.0.0-beta.2
27
+ - (package) eslint-plugin-putout v10.3.0
28
+ - (package) putout v20.3.1
29
+ - (package) supertape v6.7.4
30
+
31
+
1
32
  2021.06.12, v2.1.4
2
33
 
3
34
  fix:
package/README.md CHANGED
@@ -1,13 +1,11 @@
1
- # Redzip [![License][LicenseIMGURL]][LicenseURL] [![NPM version][NPMIMGURL]][NPMURL] [![Dependency Status][DependencyStatusIMGURL]][DependencyStatusURL] [![Build Status][BuildStatusIMGURL]][BuildStatusURL] [![Coverage Status][CoverageIMGURL]][CoverageURL]
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, {type, sort, order});
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
- "date": '2021-01-18T22:00:00.000Z',
134
- "mode": 1_107_099_648,
135
- "name": "readme.md",
136
- "owner": 0,
137
- "size": 0,
138
- "type": "file",
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.from('hello').pipe(createGzip());
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[, data], options)
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
 
@@ -1,12 +1,18 @@
1
1
  'use strict';
2
2
 
3
- const {join, basename, dirname} = require('path');
3
+ const {
4
+ join,
5
+ basename,
6
+ dirname,
7
+ } = require('path');
8
+
4
9
  const {
5
10
  createReadStream,
6
11
  createWriteStream,
7
12
  } = require('fs');
8
13
 
9
14
  const {createGunzip} = require('zlib');
15
+
10
16
  const {
11
17
  realpath,
12
18
  mkdir,
@@ -22,6 +28,7 @@ const tryToCatch = require('try-to-catch');
22
28
  const pipe = require('pipe-io');
23
29
 
24
30
  const notDir = (e) => e?.code === 'ENOTDIR';
31
+ const winNotDir = (e) => e?.code === 'ENOENT';
25
32
 
26
33
  const {assign} = Object;
27
34
 
@@ -36,25 +43,18 @@ module.exports.write = async (outerPath, innerPath, readStream, options = {}) =>
36
43
  return;
37
44
  }
38
45
 
39
- await mkdir(dirname(outerPath), {
46
+ await mkdir(dirname(outerPath), {
40
47
  recursive: true,
41
- });
48
+ });
42
49
 
43
50
  const writeStream = createWriteStream(outerPath, {
44
51
  mode,
45
52
  });
46
53
 
47
54
  if (unzip)
48
- return await pipe([
49
- readStream,
50
- createGunzip(),
51
- writeStream,
52
- ]);
53
-
54
- await pipe([
55
- readStream,
56
- writeStream,
57
- ]);
55
+ return await pipe([readStream, createGunzip(), writeStream]);
56
+
57
+ await pipe([readStream, writeStream]);
58
58
  };
59
59
 
60
60
  module.exports.readSize = async (outerPath, innerPath, options) => {
@@ -67,13 +67,18 @@ module.exports.remove = async (outerPath) => {
67
67
  if (!error)
68
68
  return;
69
69
 
70
- if (notDir(error))
70
+ if (notDir(error) || winNotDir(error)) {
71
71
  return await unlink(outerPath);
72
+ }
72
73
 
73
74
  throw error;
74
75
  };
75
76
 
76
- module.exports.read = async (path, innerPath, {type, sort, order} = {}) => {
77
+ module.exports.read = async (path, innerPath, {
78
+ type,
79
+ sort,
80
+ order,
81
+ } = {}) => {
77
82
  const [error, result] = await tryToCatch(readify, path, {
78
83
  type,
79
84
  sort,
@@ -104,11 +109,8 @@ module.exports.read = async (path, innerPath, {type, sort, order} = {}) => {
104
109
  module.exports.list = async (outerPath) => {
105
110
  const [error, names] = await tryToCatch(list, outerPath);
106
111
 
107
- if (error && error.code === 'ENOTDIR') {
108
- return [
109
- outerPath,
110
- ];
111
- }
112
+ if (notDir(error))
113
+ return [outerPath];
112
114
 
113
115
  if (error)
114
116
  throw error;
@@ -159,4 +161,3 @@ async function* walk(dir) {
159
161
  yield path;
160
162
  }
161
163
  }
162
-
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 [local, path, ''];
12
+ return [
13
+ local,
14
+ path,
15
+ '',
16
+ ];
13
17
 
14
- return [zip, outerPath, innerPath];
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
-
@@ -6,4 +6,3 @@ module.exports = async (path) => {
6
6
  const [vfs, outerPath, innerPath] = redfs(path);
7
7
  return await vfs.list(outerPath, innerPath);
8
8
  };
9
-
@@ -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,
@@ -29,4 +29,3 @@ function validate({type}) {
29
29
  if (type && type !== 'raw')
30
30
  throw Error('type should be "raw" or not to be defined!');
31
31
  }
32
-
@@ -15,4 +15,3 @@ module.exports = async (path) => {
15
15
 
16
16
  return stat;
17
17
  };
18
-
@@ -17,4 +17,3 @@ function validate({path}) {
17
17
  if (!isString(path))
18
18
  throw Error('path should be string!');
19
19
  }
20
-
@@ -22,4 +22,3 @@ function validate({path}) {
22
22
  if (!isString(path))
23
23
  throw Error('path should be string!');
24
24
  }
25
-
package/lib/zip/index.js CHANGED
@@ -15,19 +15,12 @@ module.exports.readSize = async (outerPath, innerPath, options) => {
15
15
  return await readZipSize(outerPath, innerPath, options);
16
16
  };
17
17
 
18
- module.exports.readStat = async (outerPath, innerPath) => {
19
- return await readZipStat(outerPath, innerPath);
20
- };
18
+ module.exports.readStat = readZipStat;
21
19
 
22
- module.exports.list = async (outerPath, innerPath) => {
23
- return await list(outerPath, innerPath);
24
- };
20
+ module.exports.list = list;
25
21
 
26
22
  module.exports.write = async (outerPath, innerPath, stream, options) => {
27
23
  return await writeZip(outerPath, innerPath, stream, options);
28
24
  };
29
25
 
30
- module.exports.remove = async (outerPath, innerPath) => {
31
- return await removeZip(outerPath, innerPath);
32
- };
33
-
26
+ module.exports.remove = removeZip;
@@ -3,20 +3,19 @@
3
3
  const {join} = require('path');
4
4
  const readzip = require('readzip');
5
5
 
6
- const addSlash = (a) => a[a.length - 1] === '/' ? 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 [join(outerPath, filePath)];
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
-
@@ -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[a.length - 1] === sep;
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 files;
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
-
@@ -44,4 +44,3 @@ module.exports = async (outerPath, innerPath) => {
44
44
 
45
45
  throw error;
46
46
  };
47
-
@@ -7,4 +7,3 @@ module.exports = async (outerPath, innerPath) => {
7
7
  remove: true,
8
8
  });
9
9
  };
10
-
@@ -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
- const {
9
- rename,
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,13 +1,14 @@
1
1
  {
2
2
  "name": "redzip",
3
- "version": "2.1.4",
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": "",
7
- "homepage": "http://github.com/coderaiser/readzip",
8
+ "homepage": "http://github.com/coderaiser/redzip",
8
9
  "repository": {
9
10
  "type": "git",
10
- "url": "git://github.com/coderaiser/readzip.git"
11
+ "url": "git://github.com/coderaiser/redzip.git"
11
12
  },
12
13
  "scripts": {
13
14
  "test": "madrun test",
@@ -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": "^2.0.0",
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
- "@cloudcmd/stub": "^3.1.0",
44
- "@iocmd/wait": "^1.0.0",
45
- "c8": "^7.5.0",
46
- "eslint": "^7.3.1",
47
- "eslint-plugin-node": "^11.0.0",
48
- "eslint-plugin-putout": "^8.0.1",
49
- "madrun": "^8.3.8",
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": "^2.0.2",
53
+ "nodemon": "^3.0.1",
54
54
  "pullout": "^4.0.0",
55
- "putout": "^18.0.1",
56
- "supertape": "^5.3.0"
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": ">=14"
68
+ "node": ">=16"
69
69
  },
70
70
  "license": "MIT"
71
71
  }