archiver-node 8.0.4 → 8.0.6

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.
@@ -0,0 +1,178 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports["default"] = void 0;
7
+ var _ZipArchive = _interopRequireDefault(require("../archivers/ZipArchive.js"));
8
+ var _stream = _interopRequireWildcard(require("stream"));
9
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
10
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
11
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
12
+ function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
13
+ function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
14
+ function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
15
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
16
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } // `WritableStream` doesn't work well with `archiver`.
17
+ // It breaks in certain cases. Use `PassThrough` stream instead.
18
+ // https://github.com/archiverjs/node-archiver/issues/336
19
+ // https://github.com/catamphetamine/archiver-bug
20
+ // import { WritableStream } from 'memory-streams'
21
+ var ZipArchive = exports["default"] = /*#__PURE__*/function () {
22
+ /**
23
+ * @param {object} [options] — Node.js `zlib` options such as compression level. https://nodejs.org/api/zlib. Example: `{ zlib: { level: 9 } }`.
24
+ */
25
+ function ZipArchive(options) {
26
+ var _this = this;
27
+ _classCallCheck(this, ZipArchive);
28
+ // this._outputStream = new WritableStream()
29
+ this._outputStream = new _stream.PassThrough();
30
+ var archive = new _ZipArchive["default"](options);
31
+ this._archive = archive;
32
+
33
+ // `archive` has a `.pipe()` method which kinda makes it usable as a readable stream.
34
+ // Although it's still not a "proper" implementation of a `Readable` stream.
35
+ // https://github.com/archiverjs/node-archiver/issues/765
36
+ // To get a "proper" implementation of a `Readable` stream, people use a workaround:
37
+ // `const passThroughStream = new PassThrough()` and then `archive.pipe(passThroughStream)`.
38
+
39
+ // An alternative way of how to create a `ReadableStream` from an `archive`.
40
+ // https://github.com/archiverjs/node-archiver/issues/759
41
+ //
42
+ // const readableStream = new ReadableStream({
43
+ // start(controller) {
44
+ // archive.on('data', chunk => controller.enqueue(chunk));
45
+ // archive.on('end', () => controller.close());
46
+ // archive.on('error', error => controller.error(error));
47
+ //
48
+ // archive.append(...);
49
+ // archive.append(...);
50
+ // archive.finalize();
51
+ // }
52
+ // });
53
+
54
+ // The size of the resulting archive (in bytes).
55
+ // Is `undefined` until the archive has been written.
56
+ this.size = undefined;
57
+
58
+ // A `Promise<void>` that resolves when the archive has been written.
59
+ this.promise = new Promise(function (resolve, reject) {
60
+ // Listens for all archive data to be written.
61
+ // 'close' event is fired when all data has been written.
62
+ _this._outputStream.on('close', function () {
63
+ _this.size = archive.pointer();
64
+ resolve();
65
+ });
66
+
67
+ // // Listens for all archive data to be written.
68
+ // // `end` event is fired when all archive data has been consumed by a consumer stream.
69
+ // // @see: https://nodejs.org/api/stream.html#stream_event_end
70
+ // archive.on('end', function() {
71
+ // this.size = archive.pointer()
72
+ // resolve()
73
+ // })
74
+
75
+ // Catch "warnings", whatever those're.
76
+ archive.on('warning', function (error) {
77
+ reject(error);
78
+ // The following code sample is from `archiver` README:
79
+ // if (error.code === 'ENOENT') {
80
+ // // `ENOENT` errors happen when a file or folder doesn't exist.
81
+ // // It's not clear what are the cases when it could happen.
82
+ // // And it's not clear why they're dismissed as unimportant here.
83
+ // console.warn(error)
84
+ // } else {
85
+ // reject(error)
86
+ // }
87
+ });
88
+
89
+ // Catch errors.
90
+ archive.on('error', reject);
91
+
92
+ // Pipe archive data to the output stream.
93
+ archive.pipe(_this._outputStream);
94
+ });
95
+ }
96
+
97
+ /**
98
+ * @param {(stream.Readable|Buffer|string)} content
99
+ * @param {string} internalPath — Path inside the archive
100
+ */
101
+ return _createClass(ZipArchive, [{
102
+ key: "add",
103
+ value: function add(content, internalPath) {
104
+ if (content instanceof _stream["default"]) {
105
+ // `Stream` is allowed.
106
+ } else if (content instanceof Buffer) {
107
+ // `Buffer` is allowed.
108
+ } else if (typeof content === 'string') {
109
+ // `string` is allowed.
110
+ } else {
111
+ var message = 'Unsupported type of content attempted to be added to a .zip archive';
112
+ console.log(message + ':');
113
+ console.log(content);
114
+ throw new Error(message);
115
+ }
116
+ this._archive.append(content, {
117
+ name: internalPath
118
+ });
119
+ }
120
+
121
+ /**
122
+ * @param {string} pathToFile — Path to file in the filesystem
123
+ * @param {string} internalPath — Path inside the archive
124
+ */
125
+ }, {
126
+ key: "includeFile",
127
+ value: function includeFile(pathToFile, internalPath) {
128
+ this._archive.file(pathToFile, {
129
+ name: internalPath
130
+ });
131
+ }
132
+
133
+ /**
134
+ * @param {string} pathToDirectory — Path to directory in the filesystem.
135
+ * @param {string} filePathPattern — File path "glob" pattern. Example: "file*.txt".
136
+ */
137
+ }, {
138
+ key: "includeFilesByMatch",
139
+ value: function includeFilesByMatch(pathToDirectory, filePathPattern) {
140
+ this._archive.glob(filePathPattern, {
141
+ cwd: pathToDirectory
142
+ });
143
+ }
144
+
145
+ /**
146
+ * @param {string} pathToDirectory — Path to directory in the filesystem
147
+ * @param {string} [internalPath] — Path inside the archive. Omitting this argument will put the contents of the directory to the root of the archive.
148
+ */
149
+ }, {
150
+ key: "includeDirectory",
151
+ value: function includeDirectory(pathToDirectory, internalPath) {
152
+ this._archive.directory(pathToDirectory, internalPath || false);
153
+ }
154
+
155
+ /**
156
+ * Starts the process of writing the archive file data.
157
+ * @returns {stream.Readable}
158
+ */
159
+ }, {
160
+ key: "write",
161
+ value: function write() {
162
+ // `.finalize()` starts the process of writing the archive file.
163
+ //
164
+ // `.finalize()` also returns some kind of `Promise` but it's some kind of a weird one
165
+ // and is not meant to be `await`ed or anything like that.
166
+ // https://github.com/archiverjs/node-archiver/issues/772
167
+ //
168
+ // "close", "end" or "finish" events may be fired on `this._archive`
169
+ // right after calling this method, so any required event handlers
170
+ // should have been added beforehand.
171
+ //
172
+ this._archive.finalize();
173
+
174
+ // Returns a readable `Stream` with the `.zip` archive data.
175
+ return this._outputStream;
176
+ }
177
+ }]);
178
+ }();
package/index.d.ts CHANGED
@@ -73,7 +73,7 @@ interface TransformOptions {
73
73
  objectmode?: boolean | undefined;
74
74
  }
75
75
 
76
- interface ZipOptions {
76
+ export interface ZipOptions {
77
77
  comment?: string | undefined;
78
78
  forceLocalTime?: boolean | undefined;
79
79
  forceZip64?: boolean | undefined;
package/lib/Archiver.js CHANGED
@@ -1,11 +1,6 @@
1
1
  import { createReadStream, lstat, readlinkSync, Stats } from "fs";
2
2
  import { isStream } from "is-stream";
3
- // `readdir-glob` has different exports in `esm` and `cjs`:
4
- // in `esm` it's a named export but in `cjs` it's a default export.
5
- // https://github.com/Yqnn/node-readdir-glob/issues/28
6
- // As a result, this package's code can't be transpiled properly.
7
- // Copy-pasted `readdir-glob` code here to fix that.
8
- import{ readdirGlob } from "./readdir-glob.js";
3
+ import readdirGlob from "readdir-glob";
9
4
  import { Readable } from "./lazystream.js";
10
5
  import { queue } from "async";
11
6
  import {
@@ -2,12 +2,12 @@ import Archiver from "../Archiver.js";
2
2
  import Tar from "../plugins/tar.js";
3
3
 
4
4
  export default class TarArchive extends Archiver {
5
- constructor(options) {
6
- super(options);
7
- this._format = "tar";
8
- this._module = new Tar(options);
9
- this._supportsDirectory = true;
10
- this._supportsSymlink = true;
11
- this._modulePipe();
12
- }
5
+ constructor(options) {
6
+ super(options);
7
+ this._format = "tar";
8
+ this._module = new Tar(options);
9
+ this._supportsDirectory = true;
10
+ this._supportsSymlink = true;
11
+ this._modulePipe();
12
+ }
13
13
  }
@@ -2,12 +2,12 @@ import Archiver from "../Archiver.js";
2
2
  import Zip from "../plugins/zip.js";
3
3
 
4
4
  export default class ZipArchive extends Archiver {
5
- constructor(options) {
6
- super(options);
7
- this._format = "zip";
8
- this._module = new Zip(options);
9
- this._supportsDirectory = true;
10
- this._supportsSymlink = true;
11
- this._modulePipe();
12
- }
5
+ constructor(options) {
6
+ super(options);
7
+ this._format = "zip";
8
+ this._module = new Zip(options);
9
+ this._supportsDirectory = true;
10
+ this._supportsSymlink = true;
11
+ this._modulePipe();
12
+ }
13
13
  }
@@ -0,0 +1,151 @@
1
+ import ZipArchive_ from '../archivers/ZipArchive.js'
2
+
3
+ // `WritableStream` doesn't work well with `archiver`.
4
+ // It breaks in certain cases. Use `PassThrough` stream instead.
5
+ // https://github.com/archiverjs/node-archiver/issues/336
6
+ // https://github.com/catamphetamine/archiver-bug
7
+ // import { WritableStream } from 'memory-streams'
8
+
9
+ import Stream, { PassThrough } from 'stream'
10
+
11
+ export default class ZipArchive {
12
+ /**
13
+ * @param {object} [options] — Node.js `zlib` options such as compression level. https://nodejs.org/api/zlib. Example: `{ zlib: { level: 9 } }`.
14
+ */
15
+ constructor(options) {
16
+ // this._outputStream = new WritableStream()
17
+ this._outputStream = new PassThrough()
18
+
19
+ const archive = new ZipArchive_(options)
20
+
21
+ this._archive = archive
22
+
23
+ // `archive` has a `.pipe()` method which kinda makes it usable as a readable stream.
24
+ // Although it's still not a "proper" implementation of a `Readable` stream.
25
+ // https://github.com/archiverjs/node-archiver/issues/765
26
+ // To get a "proper" implementation of a `Readable` stream, people use a workaround:
27
+ // `const passThroughStream = new PassThrough()` and then `archive.pipe(passThroughStream)`.
28
+
29
+ // An alternative way of how to create a `ReadableStream` from an `archive`.
30
+ // https://github.com/archiverjs/node-archiver/issues/759
31
+ //
32
+ // const readableStream = new ReadableStream({
33
+ // start(controller) {
34
+ // archive.on('data', chunk => controller.enqueue(chunk));
35
+ // archive.on('end', () => controller.close());
36
+ // archive.on('error', error => controller.error(error));
37
+ //
38
+ // archive.append(...);
39
+ // archive.append(...);
40
+ // archive.finalize();
41
+ // }
42
+ // });
43
+
44
+ // The size of the resulting archive (in bytes).
45
+ // Is `undefined` until the archive has been written.
46
+ this.size = undefined
47
+
48
+ // A `Promise<void>` that resolves when the archive has been written.
49
+ this.promise = new Promise((resolve, reject) => {
50
+ // Listens for all archive data to be written.
51
+ // 'close' event is fired when all data has been written.
52
+ this._outputStream.on('close', () => {
53
+ this.size = archive.pointer()
54
+ resolve()
55
+ })
56
+
57
+ // // Listens for all archive data to be written.
58
+ // // `end` event is fired when all archive data has been consumed by a consumer stream.
59
+ // // @see: https://nodejs.org/api/stream.html#stream_event_end
60
+ // archive.on('end', function() {
61
+ // this.size = archive.pointer()
62
+ // resolve()
63
+ // })
64
+
65
+ // Catch "warnings", whatever those're.
66
+ archive.on('warning', function(error) {
67
+ reject(error)
68
+ // The following code sample is from `archiver` README:
69
+ // if (error.code === 'ENOENT') {
70
+ // // `ENOENT` errors happen when a file or folder doesn't exist.
71
+ // // It's not clear what are the cases when it could happen.
72
+ // // And it's not clear why they're dismissed as unimportant here.
73
+ // console.warn(error)
74
+ // } else {
75
+ // reject(error)
76
+ // }
77
+ })
78
+
79
+ // Catch errors.
80
+ archive.on('error', reject)
81
+
82
+ // Pipe archive data to the output stream.
83
+ archive.pipe(this._outputStream)
84
+ })
85
+ }
86
+
87
+ /**
88
+ * @param {(stream.Readable|Buffer|string)} content
89
+ * @param {string} internalPath — Path inside the archive
90
+ */
91
+ add(content, internalPath) {
92
+ if (content instanceof Stream) {
93
+ // `Stream` is allowed.
94
+ } else if (content instanceof Buffer) {
95
+ // `Buffer` is allowed.
96
+ } else if (typeof content === 'string') {
97
+ // `string` is allowed.
98
+ } else {
99
+ const message = 'Unsupported type of content attempted to be added to a .zip archive'
100
+ console.log(message + ':')
101
+ console.log(content)
102
+ throw new Error(message)
103
+ }
104
+ this._archive.append(content, { name: internalPath })
105
+ }
106
+
107
+ /**
108
+ * @param {string} pathToFile — Path to file in the filesystem
109
+ * @param {string} internalPath — Path inside the archive
110
+ */
111
+ includeFile(pathToFile, internalPath) {
112
+ this._archive.file(pathToFile, { name: internalPath })
113
+ }
114
+
115
+ /**
116
+ * @param {string} pathToDirectory — Path to directory in the filesystem.
117
+ * @param {string} filePathPattern — File path "glob" pattern. Example: "file*.txt".
118
+ */
119
+ includeFilesByMatch(pathToDirectory, filePathPattern) {
120
+ this._archive.glob(filePathPattern, { cwd: pathToDirectory })
121
+ }
122
+
123
+ /**
124
+ * @param {string} pathToDirectory — Path to directory in the filesystem
125
+ * @param {string} [internalPath] — Path inside the archive. Omitting this argument will put the contents of the directory to the root of the archive.
126
+ */
127
+ includeDirectory(pathToDirectory, internalPath) {
128
+ this._archive.directory(pathToDirectory, internalPath || false);
129
+ }
130
+
131
+ /**
132
+ * Starts the process of writing the archive file data.
133
+ * @returns {stream.Readable}
134
+ */
135
+ write() {
136
+ // `.finalize()` starts the process of writing the archive file.
137
+ //
138
+ // `.finalize()` also returns some kind of `Promise` but it's some kind of a weird one
139
+ // and is not meant to be `await`ed or anything like that.
140
+ // https://github.com/archiverjs/node-archiver/issues/772
141
+ //
142
+ // "close", "end" or "finish" events may be fired on `this._archive`
143
+ // right after calling this method, so any required event handlers
144
+ // should have been added beforehand.
145
+ //
146
+ this._archive.finalize()
147
+
148
+ // Returns a readable `Stream` with the `.zip` archive data.
149
+ return this._outputStream
150
+ }
151
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "archiver-node",
3
- "version": "8.0.4",
3
+ "version": "8.0.6",
4
4
  "description": "a streaming interface for archive generation",
5
5
  "homepage": "https://github.com/catamphetamine/node-archiver",
6
6
  "author": {
@@ -24,13 +24,6 @@
24
24
  },
25
25
  "./package.json": "./package.json"
26
26
  },
27
- "files": [
28
- "index.js",
29
- "index.cjs",
30
- "index.d.ts",
31
- "lib",
32
- "cjs"
33
- ],
34
27
  "engines": {
35
28
  "node": ">=18"
36
29
  },
@@ -49,7 +42,7 @@
49
42
  "minimatch": "^10.2.2",
50
43
  "normalize-path": "^3.0.0",
51
44
  "readable-stream": "^4.7.0",
52
- "readdir-glob": "^2.0.2",
45
+ "readdir-glob": "^3.0.0",
53
46
  "tar-stream": "^3.1.7",
54
47
  "zip-stream": "^7.0.2"
55
48
  },
package/zip/index.cjs ADDED
@@ -0,0 +1 @@
1
+ module.exports = require("../cjs/exports/zip.js").default;
package/zip/index.d.ts ADDED
@@ -0,0 +1,14 @@
1
+ import * as stream from 'stream'
2
+
3
+ import { ZipOptions } from '../index.d.js';
4
+
5
+ export default class ZipArchive {
6
+ constructor(options?: ZipOptions);
7
+ add(content: stream.Readable | Buffer | string, internalPath: string): void;
8
+ includeFile(pathToFile: string, internalPath: string): void;
9
+ includeFilesByMatch(pathToDirectory: string, filePathPattern: string): void;
10
+ includeDirectory(pathToDirectory: string, internalPath?: string): void;
11
+ write(): stream.Readable;
12
+ promise: Promise<void>;
13
+ size?: number;
14
+ }
package/zip/index.js ADDED
@@ -0,0 +1 @@
1
+ export { default } from "../lib/exports/zip.js";
@@ -0,0 +1,14 @@
1
+ {
2
+ "private": true,
3
+ "name": "archiver-node/zip",
4
+ "version": "1.0.0",
5
+ "type": "module",
6
+ "exports": {
7
+ ".": {
8
+ "types": "./index.d.ts",
9
+ "import": "./index.js",
10
+ "require": "./index.cjs"
11
+ }
12
+ },
13
+ "sideEffects": false
14
+ }