redzip 3.0.5 → 4.0.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 CHANGED
@@ -1,3 +1,28 @@
1
+ 2026.02.13, v4.0.1
2
+
3
+ feature:
4
+ - 8747d2e redzip: readzip v3.0.0
5
+
6
+ 2026.01.31, v4.0.0
7
+
8
+ feature:
9
+ - 08c8a68 redzip: drop support of node < 22
10
+ - 3aec079 redzip: migrate to ESM
11
+ - 7059257 redzip: zip: get rid of mock-require
12
+ - c5326f3 redzip: zip: get rid of mock-require
13
+ - a866b39 vfs: read: get rid of mock-require
14
+ - edd168e redzip: vfs: list: get rid of mock-require
15
+ - df80143 redzip: redfs: get rid of mock-require
16
+ - e15be36 redzip: loca: get rid of mock-require
17
+ - 473851b redzip: try-to-catch v4.0.4
18
+ - d3075f7 redzip: supertape v12.2.0
19
+ - 396491d redzip: putout v41.15.0
20
+ - 1710c13 redzip: madrun v12.1.3
21
+ - 881e3f7 redzip: eslint-plugin-putout v30.0.1
22
+ - 2283519 redzip: putout v37.1.1
23
+ - 6da11c0 redzip: eslint-plugin-putout v23.3.0
24
+ - 11e5e56 redzip: yazl v3.3.1
25
+
1
26
  2024.08.16, v3.0.5
2
27
 
3
28
  feature:
package/README.md CHANGED
@@ -32,15 +32,14 @@ npm i redzip
32
32
  #### Example
33
33
 
34
34
  ```js
35
+ import * as redzip from 'redzip';
36
+
35
37
  const sort = 'size';
36
38
  const order = 'desc';
37
39
  const type = 'raw';
38
-
39
40
  const dirPath = '/home/coderaiser/hello.zip/hello/';
40
41
  const path = '/home/coderaiser/hello.zip/hello.txt';
41
42
 
42
- const redzip = require('redzip');
43
-
44
43
  const dirStream = await redzip.read(dirPath, {
45
44
  type,
46
45
  sort,
@@ -1,38 +1,32 @@
1
- 'use strict';
2
-
3
- const {
1
+ import {
4
2
  join,
5
3
  basename,
6
4
  dirname,
7
- } = require('node:path');
8
-
9
- const {
10
- createReadStream,
5
+ } from 'node:path';
6
+ import {
7
+ createReadStream as _createReadStream,
11
8
  createWriteStream,
12
- } = require('node:fs');
13
-
14
- const {createGunzip} = require('node:zlib');
15
-
16
- const {
17
- realpath,
9
+ } from 'node:fs';
10
+ import {createGunzip} from 'node:zlib';
11
+ import {
12
+ realpath as _realpath,
18
13
  mkdir,
19
- rmdir,
20
- unlink,
14
+ rmdir as _rmdir,
15
+ unlink as _unlink,
21
16
  lstat,
22
17
  opendir,
23
- } = require('node:fs/promises');
24
-
25
- const readify = require('readify');
26
- const trammel = require('trammel');
27
- const tryToCatch = require('try-to-catch');
28
- const pipe = require('pipe-io');
18
+ } from 'node:fs/promises';
19
+ import readify from 'readify';
20
+ import trammel from 'trammel';
21
+ import {tryToCatch} from 'try-to-catch';
22
+ import pipe from 'pipe-io';
29
23
 
30
24
  const notDir = (e) => e?.code === 'ENOTDIR';
31
25
  const winNotDir = (e) => e?.code === 'ENOENT';
32
26
 
33
27
  const {assign} = Object;
34
28
 
35
- module.exports.write = async (outerPath, innerPath, readStream, options = {}) => {
29
+ export const write = async (outerPath, innerPath, readStream, options = {}) => {
36
30
  const {unzip, mode} = options;
37
31
 
38
32
  if (!readStream) {
@@ -57,11 +51,15 @@ module.exports.write = async (outerPath, innerPath, readStream, options = {}) =>
57
51
  await pipe([readStream, writeStream]);
58
52
  };
59
53
 
60
- module.exports.readSize = async (outerPath, innerPath, options) => {
54
+ export const readSize = async (outerPath, innerPath, options) => {
61
55
  return await trammel(outerPath, options);
62
56
  };
63
57
 
64
- module.exports.remove = async (outerPath) => {
58
+ export const remove = async (outerPath, overrides = {}) => {
59
+ const {
60
+ rmdir = _rmdir,
61
+ unlink = _unlink,
62
+ } = overrides;
65
63
  const [error] = await tryToCatch(rmdir, outerPath);
66
64
 
67
65
  if (!error)
@@ -73,7 +71,15 @@ module.exports.remove = async (outerPath) => {
73
71
  throw error;
74
72
  };
75
73
 
76
- module.exports.read = async (path, innerPath, {type, sort, order} = {}) => {
74
+ export const read = async (path, innerPath, overrides = {}) => {
75
+ const {
76
+ type,
77
+ sort,
78
+ order,
79
+ createReadStream = _createReadStream,
80
+ realpath = _realpath,
81
+ } = overrides;
82
+
77
83
  const [error, result] = await tryToCatch(readify, path, {
78
84
  type,
79
85
  sort,
@@ -101,8 +107,8 @@ module.exports.read = async (path, innerPath, {type, sort, order} = {}) => {
101
107
  return result.files;
102
108
  };
103
109
 
104
- module.exports.list = async (outerPath) => {
105
- const [error, names] = await tryToCatch(list, outerPath);
110
+ export const list = async (outerPath) => {
111
+ const [error, names] = await tryToCatch(listAll, outerPath);
106
112
 
107
113
  if (notDir(error))
108
114
  return [outerPath];
@@ -113,7 +119,7 @@ module.exports.list = async (outerPath) => {
113
119
  return names;
114
120
  };
115
121
 
116
- async function list(outerPath) {
122
+ async function listAll(outerPath) {
117
123
  const names = [];
118
124
 
119
125
  for await (const name of await walk(outerPath)) {
@@ -123,7 +129,7 @@ async function list(outerPath) {
123
129
  return names;
124
130
  }
125
131
 
126
- module.exports.readStat = async (outerPath) => {
132
+ export const readStat = async (outerPath) => {
127
133
  const statResult = await lstat(outerPath);
128
134
  const {
129
135
  mtime,
package/lib/redfs.js CHANGED
@@ -1,12 +1,12 @@
1
- 'use strict';
1
+ import {sep as _sep} from 'node:path';
2
+ import * as zip from './zip/index.js';
3
+ import * as local from './local/index.js';
2
4
 
3
- const {sep} = require('node:path');
4
-
5
- const zip = require('./zip');
6
- const local = require('./local');
7
-
8
- module.exports = (path) => {
9
- const [outerPath, innerPath] = split(path);
5
+ export default (path, overrides = {}) => {
6
+ const {sep = _sep} = overrides;
7
+ const [outerPath, innerPath] = split(path, {
8
+ sep,
9
+ });
10
10
 
11
11
  if (!innerPath)
12
12
  return [
@@ -22,7 +22,7 @@ module.exports = (path) => {
22
22
  ];
23
23
  };
24
24
 
25
- function split(path) {
25
+ function split(path, {sep}) {
26
26
  const replaced = path.replace(`.zip${sep}`, `*${sep}`);
27
27
  let [outer, inner = ''] = replaced.split('*');
28
28
 
package/lib/redzip.js CHANGED
@@ -1,15 +1,6 @@
1
- 'use strict';
2
-
3
- const read = require('./vfs/read');
4
- const readSize = require('./vfs/read-size');
5
- const readStat = require('./vfs/read-stat');
6
- const list = require('./vfs/list');
7
- const write = require('./vfs/write');
8
- const remove = require('./vfs/remove');
9
-
10
- module.exports.read = read;
11
- module.exports.readSize = readSize;
12
- module.exports.readStat = readStat;
13
- module.exports.list = list;
14
- module.exports.write = write;
15
- module.exports.remove = remove;
1
+ export {read} from './vfs/read/index.js';
2
+ export {readSize} from './vfs/read-size/index.js';
3
+ export {readStat} from './vfs/read-stat/index.js';
4
+ export {list} from './vfs/list/index.js';
5
+ export {write} from './vfs/write/index.js';
6
+ export {remove} from './vfs/remove/index.js';
@@ -1,8 +1,8 @@
1
- 'use strict';
1
+ import _redfs from '../../redfs.js';
2
2
 
3
- const redfs = require('../../redfs');
4
-
5
- module.exports = async (path) => {
3
+ export const list = async (path, overrides = {}) => {
4
+ const {redfs = _redfs} = overrides;
6
5
  const [vfs, outerPath, innerPath] = redfs(path);
6
+
7
7
  return await vfs.list(outerPath, innerPath);
8
8
  };
@@ -1,22 +1,22 @@
1
- 'use strict';
2
-
3
- const {normalize} = require('node:path');
4
- const {Readable} = require('node:stream');
5
- const {addSlashToEnd} = require('format-io');
6
-
7
- const redfs = require('../../redfs');
1
+ import {Buffer} from 'node:buffer';
2
+ import {normalize} from 'node:path';
3
+ import {Readable} from 'node:stream';
4
+ import {addSlashToEnd} from 'format-io';
5
+ import _redfs from '../../redfs.js';
8
6
 
9
7
  const {assign} = Object;
10
8
  const {stringify} = JSON;
11
9
  const isString = (a) => typeof a === 'string';
12
10
  const preparePath = (a, b) => normalize(addSlashToEnd(a).replace(b, '/'));
13
11
 
14
- module.exports = async (path, options = {}) => {
12
+ export const read = async (path, options = {}) => {
15
13
  const {
16
14
  root = '/',
17
15
  order = 'asc',
18
16
  sort = 'name',
19
17
  type,
18
+ redfs = _redfs,
19
+ realpath,
20
20
  } = options;
21
21
 
22
22
  validate({
@@ -32,6 +32,7 @@ module.exports = async (path, options = {}) => {
32
32
  type,
33
33
  sort,
34
34
  order,
35
+ realpath,
35
36
  });
36
37
 
37
38
  const currentPath = preparePath(path, root);
@@ -1,11 +1,10 @@
1
- 'use strict';
2
-
3
- const {Readable} = require('node:stream');
4
- const redfs = require('../../redfs');
1
+ import {Buffer} from 'node:buffer';
2
+ import {Readable} from 'node:stream';
3
+ import redfs from '../../redfs.js';
5
4
 
6
5
  const {assign} = Object;
7
6
 
8
- module.exports = async (path, options = {}) => {
7
+ export const readSize = async (path, options = {}) => {
9
8
  const {type} = options;
10
9
 
11
10
  validate({
@@ -1,11 +1,9 @@
1
- 'use strict';
2
-
3
- const redfs = require('../../redfs');
1
+ import redfs from '../../redfs.js';
4
2
 
5
3
  const buildIsDirectory = ({type}) => () => type === 'dir';
6
4
  const {assign} = Object;
7
5
 
8
- module.exports = async (path) => {
6
+ export const readStat = async (path) => {
9
7
  const [vfs, outerPath, innerPath] = redfs(path);
10
8
  const stat = await vfs.readStat(outerPath, innerPath);
11
9
 
@@ -1,10 +1,8 @@
1
- 'use strict';
2
-
3
- const redfs = require('../../redfs');
1
+ import redfs from '../../redfs.js';
4
2
 
5
3
  const isString = (a) => typeof a === 'string';
6
4
 
7
- module.exports = async (path) => {
5
+ export const remove = async (path) => {
8
6
  validate({
9
7
  path,
10
8
  });
@@ -1,13 +1,10 @@
1
- 'use strict';
2
-
3
- const {Readable} = require('node:stream');
4
- const {basename} = require('node:path');
5
-
6
- const redfs = require('../../redfs');
1
+ import {Readable} from 'node:stream';
2
+ import {basename} from 'node:path';
3
+ import redfs from '../../redfs.js';
7
4
 
8
5
  const isString = (a) => typeof a === 'string';
9
6
 
10
- module.exports = async (path, data, options) => {
7
+ export const write = async (path, data, options) => {
11
8
  validate({
12
9
  path,
13
10
  });
package/lib/zip/index.js CHANGED
@@ -1,26 +1,23 @@
1
- 'use strict';
1
+ import readZip from './read/index.js';
2
+ import readZipSize from './read-size/index.js';
3
+ import readZipStat from './read-stat/index.js';
2
4
 
3
- const readZip = require('./read');
4
- const readZipSize = require('./read-size');
5
- const readZipStat = require('./read-stat');
6
- const list = require('./list');
7
- const writeZip = require('./write');
8
- const removeZip = require('./remove');
5
+ export {list} from './list/index.js';
6
+ import writeZip from './write/index.js';
7
+ import removeZip from './remove/index.js';
9
8
 
10
- module.exports.read = async (outerPath, innerPath, options) => {
9
+ export const read = async (outerPath, innerPath, options) => {
11
10
  return await readZip(outerPath, innerPath, options);
12
11
  };
13
12
 
14
- module.exports.readSize = async (outerPath, innerPath, options) => {
13
+ export const readSize = async (outerPath, innerPath, options) => {
15
14
  return await readZipSize(outerPath, innerPath, options);
16
15
  };
17
16
 
18
- module.exports.readStat = readZipStat;
17
+ export const readStat = readZipStat;
19
18
 
20
- module.exports.list = list;
21
-
22
- module.exports.write = async (outerPath, innerPath, stream, options) => {
19
+ export const write = async (outerPath, innerPath, stream, options) => {
23
20
  return await writeZip(outerPath, innerPath, stream, options);
24
21
  };
25
22
 
26
- module.exports.remove = removeZip;
23
+ export const remove = removeZip;
@@ -1,11 +1,9 @@
1
- 'use strict';
2
-
3
- const {join} = require('node:path');
4
- const readzip = require('readzip');
1
+ import {join} from 'node:path';
2
+ import {readzip} from 'readzip';
5
3
 
6
4
  const addSlash = (a) => a.at(-1) === '/' ? a : `${a}/`;
7
5
 
8
- module.exports = async (outerPath, innerPath) => {
6
+ export const list = async (outerPath, innerPath) => {
9
7
  const paths = [];
10
8
  const rootDir = addSlash(innerPath);
11
9
 
@@ -1,10 +1,9 @@
1
- 'use strict';
1
+ import {posix} from 'node:path';
2
+ import sortify from '@cloudcmd/sortify';
3
+ import formatify from '@cloudcmd/formatify';
4
+ import {readzip} from 'readzip';
2
5
 
3
- const {sep} = require('node:path').posix;
4
-
5
- const sortify = require('@cloudcmd/sortify');
6
- const formatify = require('@cloudcmd/formatify');
7
- const readzip = require('readzip');
6
+ const {sep} = posix;
8
7
 
9
8
  const ifRaw = (type, fn, a) => type === 'raw' ? a : fn(a);
10
9
  const isEndSlash = (a) => a.at(-1) === sep;
@@ -12,7 +11,7 @@ const addSlash = (a) => isEndSlash(a) ? a : `${a}${sep}`;
12
11
 
13
12
  const {assign} = Object;
14
13
 
15
- module.exports = async (outerPath, innerPath, options = {}) => {
14
+ export default async (outerPath, innerPath, options = {}) => {
16
15
  const inner = addSlash(innerPath);
17
16
  const {
18
17
  type,
@@ -1,9 +1,7 @@
1
- 'use strict';
1
+ import format from 'format-io';
2
+ import {readzip} from 'readzip';
2
3
 
3
- const format = require('format-io');
4
- const readzip = require('readzip');
5
-
6
- module.exports = async (outerPath, innerPath, options = {}) => {
4
+ export default async (outerPath, innerPath, options = {}) => {
7
5
  const {type} = options;
8
6
 
9
7
  let sum = 0;
@@ -1,10 +1,8 @@
1
- 'use strict';
2
-
3
- const readzip = require('readzip');
1
+ import {readzip} from 'readzip';
4
2
 
5
3
  const {assign} = Object;
6
4
 
7
- module.exports = async (outerPath, innerPath) => {
5
+ export default async (outerPath, innerPath) => {
8
6
  for await (const path of readzip(outerPath)) {
9
7
  const {
10
8
  name,
@@ -1,8 +1,6 @@
1
- 'use strict';
1
+ import write from '../write/index.js';
2
2
 
3
- const write = require('../write');
4
-
5
- module.exports = async (outerPath, innerPath) => {
3
+ export default async (outerPath, innerPath) => {
6
4
  await write(outerPath, innerPath, null, {
7
5
  remove: true,
8
6
  });
@@ -1,17 +1,18 @@
1
- 'use strict';
1
+ import {once} from 'node:events';
2
+ import {promisify} from 'node:util';
3
+ import {posix} from 'node:path';
4
+ import {createWriteStream} from 'node:fs';
5
+ import {createGunzip} from 'node:zlib';
6
+ import {
7
+ rename as _rename,
8
+ unlink,
9
+ } from 'node:fs/promises';
10
+ import yazl from 'yazl';
11
+ import pipe from 'pipe-io';
12
+ import {tryToCatch} from 'try-to-catch';
13
+ import {readzip} from 'readzip';
2
14
 
3
- const {once} = require('node:events');
4
- const {promisify} = require('node:util');
5
- const {join, dirname} = require('node:path').posix;
6
- const {createWriteStream} = require('node:fs');
7
- const {createGunzip} = require('node:zlib');
8
-
9
- const {rename, unlink} = require('node:fs/promises');
10
-
11
- const yazl = require('yazl');
12
- const pipe = require('pipe-io');
13
- const tryToCatch = require('try-to-catch');
14
- const readzip = require('readzip');
15
+ const {join, dirname} = posix;
15
16
 
16
17
  const {round, random} = Math;
17
18
 
@@ -22,12 +23,17 @@ const end = promisify((zipfile, fn) => {
22
23
  });
23
24
  });
24
25
 
25
- module.exports = async (outerPath, innerPath, stream, options = {}) => {
26
+ export default async (outerPath, innerPath, stream, options = {}) => {
27
+ const {
28
+ rename = _rename,
29
+ unzip,
30
+ remove,
31
+ } = options;
32
+
26
33
  const tmpName = join(dirname(outerPath), `.redzip-${getRandom()}.zip`);
27
34
 
28
35
  const zipfile = new yazl.ZipFile();
29
36
  const {outputStream} = zipfile;
30
- const {unzip, remove} = options;
31
37
 
32
38
  let readStream;
33
39
 
@@ -38,7 +44,9 @@ module.exports = async (outerPath, innerPath, stream, options = {}) => {
38
44
  update(outerPath, innerPath, readStream, zipfile, {
39
45
  remove,
40
46
  }),
41
- replace(outerPath, tmpName, outputStream),
47
+ replace(outerPath, tmpName, outputStream, {
48
+ rename,
49
+ }),
42
50
  ]);
43
51
 
44
52
  if (!readStream) {
@@ -94,7 +102,7 @@ async function update(outerPath, innerPath, stream, zipfile, {remove}) {
94
102
  await end(zipfile);
95
103
  }
96
104
 
97
- async function replace(outerPath, name, stream) {
105
+ async function replace(outerPath, name, stream, {rename}) {
98
106
  const writeStream = createWriteStream(name);
99
107
 
100
108
  await pipe([stream, writeStream]);
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "redzip",
3
- "version": "3.0.5",
4
- "type": "commonjs",
3
+ "version": "4.0.1",
4
+ "type": "module",
5
5
  "main": "lib/redzip.js",
6
6
  "description": "work with files inside archives like with regular files",
7
7
  "author": "",
8
8
  "homepage": "http://github.com/coderaiser/redzip",
9
9
  "repository": {
10
10
  "type": "git",
11
- "url": "git://github.com/coderaiser/redzip.git"
11
+ "url": "git+https://github.com/coderaiser/redzip.git"
12
12
  },
13
13
  "scripts": {
14
14
  "test": "madrun test",
@@ -30,29 +30,27 @@
30
30
  "once": "^1.4.0",
31
31
  "pipe-io": "^4.0.1",
32
32
  "readify": "^10.0.0",
33
- "readzip": "^2.0.0",
33
+ "readzip": "^3.0.0",
34
34
  "totalist": "^3.0.1",
35
35
  "trammel": "^6.0.0",
36
- "try-to-catch": "^3.0.0",
36
+ "try-to-catch": "^4.0.4",
37
37
  "wraptile": "^3.0.0",
38
38
  "yauzl": "^3.1.2",
39
- "yazl": "^2.5.1"
39
+ "yazl": "^3.3.1"
40
40
  },
41
41
  "devDependencies": {
42
- "@babel/core": "^7.12.10",
43
- "@babel/eslint-parser": "^7.12.1",
44
42
  "@iocmd/wait": "^2.1.0",
45
43
  "c8": "^10.1.2",
46
44
  "eslint": "^9.9.0",
47
- "eslint-plugin-putout": "^22.4.1",
48
- "madrun": "^10.0.1",
45
+ "eslint-plugin-putout": "^30.0.1",
46
+ "madrun": "^12.1.3",
49
47
  "memfs": "^4.2.1",
50
48
  "mock-fs": "^5.0.0",
51
- "mock-require": "^3.0.1",
52
49
  "nodemon": "^3.0.1",
53
50
  "pullout": "^5.0.1",
54
- "putout": "^36.0.4",
55
- "supertape": "^10.4.0"
51
+ "putout": "^41.15.0",
52
+ "redlint": "^5.4.0",
53
+ "supertape": "^12.2.0"
56
54
  },
57
55
  "keywords": [
58
56
  "directory",
@@ -64,7 +62,7 @@
64
62
  "zip"
65
63
  ],
66
64
  "engines": {
67
- "node": ">=18"
65
+ "node": ">=22"
68
66
  },
69
67
  "license": "MIT"
70
68
  }