archiver-node 8.0.0 → 8.0.2

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/cjs/utils.js ADDED
@@ -0,0 +1,92 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+ var utils_exports = {};
29
+ __export(utils_exports, {
30
+ collectStream: () => collectStream,
31
+ dateify: () => dateify,
32
+ normalizeInputSource: () => normalizeInputSource,
33
+ sanitizePath: () => sanitizePath,
34
+ trailingSlashIt: () => trailingSlashIt
35
+ });
36
+ module.exports = __toCommonJS(utils_exports);
37
+ var import_normalize_path = __toESM(require("normalize-path"), 1);
38
+ var import_readable_stream = require("readable-stream");
39
+ var import_is_stream = require("is-stream");
40
+ function collectStream(source, callback) {
41
+ var collection = [];
42
+ var size = 0;
43
+ source.on("error", callback);
44
+ source.on("data", function(chunk) {
45
+ collection.push(chunk);
46
+ size += chunk.length;
47
+ });
48
+ source.on("end", function() {
49
+ var buf = Buffer.alloc(size);
50
+ var offset = 0;
51
+ collection.forEach(function(data) {
52
+ data.copy(buf, offset);
53
+ offset += data.length;
54
+ });
55
+ callback(null, buf);
56
+ });
57
+ }
58
+ function dateify(dateish) {
59
+ dateish = dateish || /* @__PURE__ */ new Date();
60
+ if (dateish instanceof Date) {
61
+ dateish = dateish;
62
+ } else if (typeof dateish === "string") {
63
+ dateish = new Date(dateish);
64
+ } else {
65
+ dateish = /* @__PURE__ */ new Date();
66
+ }
67
+ return dateish;
68
+ }
69
+ function normalizeInputSource(source) {
70
+ if (source === null) {
71
+ return Buffer.alloc(0);
72
+ } else if (typeof source === "string") {
73
+ return Buffer.from(source);
74
+ } else if ((0, import_is_stream.isStream)(source, { canOpen: false })) {
75
+ return source.pipe(new import_readable_stream.PassThrough());
76
+ }
77
+ return source;
78
+ }
79
+ function sanitizePath(filepath) {
80
+ return (0, import_normalize_path.default)(filepath, false).replace(/^\w+:/, "").replace(/^(\.\.\/|\/)+/, "");
81
+ }
82
+ function trailingSlashIt(str) {
83
+ return str.slice(-1) !== "/" ? str + "/" : str;
84
+ }
85
+ // Annotate the CommonJS export names for ESM import in node:
86
+ 0 && (module.exports = {
87
+ collectStream,
88
+ dateify,
89
+ normalizeInputSource,
90
+ sanitizePath,
91
+ trailingSlashIt
92
+ });
package/index.cjs ADDED
@@ -0,0 +1,4 @@
1
+ exports.Archiver = require("./cjs/Archiver.js").default;
2
+ exports.JsonArchive = require("./cjs/archivers/JsonArchive.js").default;
3
+ exports.TarArchive = require("./cjs/archivers/TarArchive.js").default;
4
+ exports.ZipArchive = require("./cjs/archivers/ZipArchive.js").default;
package/index.d.ts ADDED
@@ -0,0 +1,138 @@
1
+ // Copy-pasted from `DefinitelyTyped` on 23.02.2026:
2
+ // https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/archiver/index.d.ts
3
+
4
+ import * as fs from "fs";
5
+ import * as stream from "stream";
6
+ import * as ReaddirGlob from "readdir-glob";
7
+ import { ZlibOptions } from "zlib";
8
+
9
+ // This library adds `cwd` to the options
10
+ type GlobOptions = ReaddirGlob.Options & { cwd?: string };
11
+
12
+ interface EntryData {
13
+ /** Sets the entry name including internal path */
14
+ name: string;
15
+ /** Sets the entry date */
16
+ date?: Date | string | undefined;
17
+ /** Sets the entry permissions */
18
+ mode?: number | undefined;
19
+ /**
20
+ * Sets a path prefix for the entry name.
21
+ * Useful when working with methods like `directory` or `glob`
22
+ */
23
+ prefix?: string | undefined;
24
+ /**
25
+ * Sets the fs stat data for this entry allowing
26
+ * for reduction of fs stat calls when stat data is already known
27
+ */
28
+ stats?: fs.Stats | undefined;
29
+ }
30
+
31
+ interface ZipEntryData extends EntryData {
32
+ /** Sets the compression method to STORE */
33
+ store?: boolean | undefined;
34
+ }
35
+
36
+ type TarEntryData = EntryData;
37
+
38
+ interface ProgressData {
39
+ entries: {
40
+ total: number;
41
+ processed: number;
42
+ };
43
+ fs: {
44
+ totalBytes: number;
45
+ processedBytes: number;
46
+ };
47
+ }
48
+
49
+ /** A function that lets you either opt out of including an entry (by returning false), or modify the contents of an entry as it is added (by returning an EntryData) */
50
+ type EntryDataFunction = (entry: EntryData) => false | EntryData;
51
+
52
+ class ArchiverError extends Error {
53
+ code: string; // Since archiver format support is modular, we cannot enumerate all possible error codes, as the modules can throw arbitrary ones.
54
+ data: any;
55
+ path?: any;
56
+
57
+ constructor(code: string, data: any);
58
+ }
59
+
60
+ type ArchiverOptions = CoreOptions & TransformOptions;
61
+
62
+ interface CoreOptions {
63
+ statConcurrency?: number | undefined;
64
+ }
65
+
66
+ interface TransformOptions {
67
+ allowHalfOpen?: boolean | undefined;
68
+ readableObjectMode?: boolean | undefined;
69
+ writeableObjectMode?: boolean | undefined;
70
+ decodeStrings?: boolean | undefined;
71
+ encoding?: string | undefined;
72
+ highWaterMark?: number | undefined;
73
+ objectmode?: boolean | undefined;
74
+ }
75
+
76
+ interface ZipOptions {
77
+ comment?: string | undefined;
78
+ forceLocalTime?: boolean | undefined;
79
+ forceZip64?: boolean | undefined;
80
+ /** @default false */
81
+ namePrependSlash?: boolean | undefined;
82
+ store?: boolean | undefined;
83
+ zlib?: ZlibOptions | undefined;
84
+ }
85
+
86
+ interface TarOptions {
87
+ gzip?: boolean | undefined;
88
+ gzipOptions?: ZlibOptions | undefined;
89
+ }
90
+
91
+ export class Archiver extends stream.Transform {
92
+ _format: string;
93
+ _module: Module;
94
+ _supportsDirectory: boolean;
95
+ _supportsSymlink: boolean;
96
+ _modulePipe: () => void;
97
+
98
+ constructor(options?: ArchiverOptions);
99
+
100
+ abort(): this;
101
+ append(source: stream.Readable | Buffer | string, data?: EntryData | ZipEntryData | TarEntryData): this;
102
+
103
+ /** if false is passed for destpath, the path of a chunk of data in the archive is set to the root */
104
+ directory(dirpath: string, destpath: false | string, data?: Partial<EntryData> | EntryDataFunction): this;
105
+ file(filename: string, data: EntryData): this;
106
+ glob(pattern: string, options?: GlobOptions, data?: Partial<EntryData>): this;
107
+ finalize(): Promise<void>;
108
+
109
+ setFormat(format: string): this;
110
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
111
+ setModule(module: Function): this;
112
+
113
+ pointer(): number;
114
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
115
+ use(plugin: Function): this;
116
+
117
+ symlink(filepath: string, target: string, mode?: number): this;
118
+
119
+ on(event: "error" | "warning", listener: (error: ArchiverError) => void): this;
120
+ on(event: "data", listener: (data: Buffer) => void): this;
121
+ on(event: "progress", listener: (progress: ProgressData) => void): this;
122
+ on(event: "close" | "drain" | "finish", listener: () => void): this;
123
+ on(event: "pipe" | "unpipe", listener: (src: stream.Readable) => void): this;
124
+ on(event: "entry", listener: (entry: EntryData) => void): this;
125
+ on(event: string, listener: (...args: any[]) => void): this;
126
+ }
127
+
128
+ export class ZipArchive extends Archiver {
129
+ constructor(options?: ArchiverOptions & ZipOptions);
130
+ }
131
+
132
+ export class TarArchive extends Archiver {
133
+ constructor(options?: ArchiverOptions & TarOptions);
134
+ }
135
+
136
+ export class JsonArchive extends Archiver {
137
+ constructor(options?: ArchiverOptions);
138
+ }
package/index.js CHANGED
@@ -1,39 +1,4 @@
1
- import Archiver from "./lib/core.js";
2
- import Zip from "./lib/plugins/zip.js";
3
- import Tar from "./lib/plugins/tar.js";
4
- import Json from "./lib/plugins/json.js";
5
-
6
- export { Archiver };
7
-
8
- export class ZipArchive extends Archiver {
9
- constructor(options) {
10
- super(options);
11
- this._format = "zip";
12
- this._module = new Zip(options);
13
- this._supportsDirectory = true;
14
- this._supportsSymlink = true;
15
- this._modulePipe();
16
- }
17
- }
18
-
19
- export class TarArchive extends Archiver {
20
- constructor(options) {
21
- super(options);
22
- this._format = "tar";
23
- this._module = new Tar(options);
24
- this._supportsDirectory = true;
25
- this._supportsSymlink = true;
26
- this._modulePipe();
27
- }
28
- }
29
-
30
- export class JsonArchive extends Archiver {
31
- constructor(options) {
32
- super(options);
33
- this._format = "json";
34
- this._module = new Json(options);
35
- this._supportsDirectory = true;
36
- this._supportsSymlink = true;
37
- this._modulePipe();
38
- }
39
- }
1
+ export { default as Archiver } from "./lib/Archiver.js";
2
+ export { default as JsonArchive } from "./lib/archivers/JsonArchive.js";
3
+ export { default as TarArchive } from "./lib/archivers/TarArchive.js";
4
+ export { default as ZipArchive } from "./lib/archivers/ZipArchive.js";
@@ -1,7 +1,7 @@
1
1
  import { createReadStream, lstat, readlinkSync, Stats } from "fs";
2
2
  import { isStream } from "is-stream";
3
3
  import { readdirGlob } from "readdir-glob";
4
- import { Readable } from "lazystream";
4
+ import { Readable } from "./lazystream.js";
5
5
  import { queue } from "async";
6
6
  import {
7
7
  dirname,
@@ -0,0 +1,13 @@
1
+ import Archiver from "../Archiver.js";
2
+ import Json from "../plugins/json.js";
3
+
4
+ export default class JsonArchive extends Archiver {
5
+ constructor(options) {
6
+ super(options);
7
+ this._format = "json";
8
+ this._module = new Json(options);
9
+ this._supportsDirectory = true;
10
+ this._supportsSymlink = true;
11
+ this._modulePipe();
12
+ }
13
+ }
@@ -0,0 +1,13 @@
1
+ import Archiver from "../Archiver.js";
2
+ import Tar from "../plugins/tar.js";
3
+
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
+ }
13
+ }
@@ -0,0 +1,13 @@
1
+ import Archiver from "../Archiver.js";
2
+ import Zip from "../plugins/zip.js";
3
+
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
+ }
13
+ }
@@ -0,0 +1,91 @@
1
+ // Copy-pasted from an unmerged pull request in `lazystream` repo on 23.02.2026:
2
+ // https://github.com/jpommerening/node-lazystream/pull/9/changes
3
+ //
4
+ // That pull request fixes the dependency on `readable-stream` library.
5
+ // https://github.com/jpommerening/node-lazystream/issues/7
6
+ // It wasn't merged because it would have to be a "breaking change" in term of Node.js version requirement
7
+ // and also `lazystream` package seems to no longer be maintained anyway.
8
+
9
+ import { PassThrough } from 'stream';
10
+
11
+ // Patch the given method of instance so that the callback
12
+ // is executed once, before the actual method is called the
13
+ // first time.
14
+ function beforeFirstCall(instance, method, callback) {
15
+ instance[method] = function(...args) {
16
+ delete instance[method];
17
+ callback.apply(this, args);
18
+ return this[method].apply(this, args);
19
+ };
20
+ }
21
+
22
+ export class Readable extends PassThrough {
23
+ constructor(fn, options) {
24
+ super(options);
25
+
26
+ // Support calling without new
27
+ if (!(this instanceof Readable)) {
28
+ return new Readable(fn, options);
29
+ }
30
+
31
+ beforeFirstCall(this, '_read', function() {
32
+ const source = fn.call(this, options);
33
+ const emit = this.emit.bind(this, 'error');
34
+ source.on('error', emit);
35
+ source.pipe(this);
36
+ });
37
+
38
+ this.emit('readable');
39
+ }
40
+ }
41
+
42
+ export class Writable extends PassThrough {
43
+ constructor(fn, options) {
44
+ super(options);
45
+
46
+ // Support calling without new
47
+ if (!(this instanceof Writable)) {
48
+ return new Writable(fn, options);
49
+ }
50
+
51
+ beforeFirstCall(this, '_write', function() {
52
+ const destination = fn.call(this, options);
53
+ const emit = this.emit.bind(this, 'error');
54
+ destination.on('error', emit);
55
+ this.pipe(destination);
56
+ });
57
+
58
+ this.emit('writable');
59
+ }
60
+ }
61
+
62
+ // An alternative suggested by Google AI:
63
+ //
64
+ // function createLazyReadStream(filePath) {
65
+ // const passthrough = new PassThrough();
66
+ // let underlyingStream = null;
67
+ //
68
+ // // This function is called only when the stream is first consumed (e.g., piped or 'data' event listener added)
69
+ // const initializeStream = () => {
70
+ // if (!underlyingStream) {
71
+ // underlyingStream = fs.createReadStream(filePath);
72
+ // // Pipe the real stream's data through the passthrough stream
73
+ // underlyingStream.pipe(passthrough);
74
+ //
75
+ // // Forward error events
76
+ // underlyingStream.on('error', (err) => passthrough.emit('error', err));
77
+ // }
78
+ // };
79
+ //
80
+ // // Intercept the 'data' event listener or 'pipe' method to initialize the stream
81
+ // passthrough.on('newListener', (event) => {
82
+ // if (event === 'data' || event === 'pipe') {
83
+ // initializeStream();
84
+ // }
85
+ // });
86
+ //
87
+ // // You also need to handle cases where 'read()' is called directly.
88
+ // // This is a bit more complex, but the 'newListener' approach covers most common use cases.
89
+ //
90
+ // return passthrough;
91
+ // }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "archiver-node",
3
- "version": "8.0.0",
3
+ "version": "8.0.2",
4
4
  "description": "a streaming interface for archive generation",
5
5
  "homepage": "https://github.com/catamphetamine/node-archiver",
6
6
  "author": {
@@ -16,15 +16,29 @@
16
16
  },
17
17
  "license": "MIT",
18
18
  "type": "module",
19
- "exports": "./index.js",
19
+ "exports": {
20
+ ".": {
21
+ "types": "./index.d.ts",
22
+ "import": "./index.js",
23
+ "require": "./index.cjs"
24
+ },
25
+ "./package.json": "./package.json"
26
+ },
20
27
  "files": [
21
28
  "index.js",
22
- "lib"
29
+ "index.cjs",
30
+ "index.d.ts",
31
+ "lib",
32
+ "cjs"
23
33
  ],
24
34
  "engines": {
25
35
  "node": ">=18"
26
36
  },
27
37
  "scripts": {
38
+ "build:clean": "rimraf cjs",
39
+ "build:cjs": "esbuild lib/**/*.js --outdir=cjs --platform=node --format=cjs",
40
+ "build:cjs:package.json": "node scripts/create-commonjs-package-json.js",
41
+ "build": "npm-run-all build:clean build:cjs build:cjs:package.json",
28
42
  "test": "mocha --reporter dot",
29
43
  "bench": "node benchmark/simple/pack-zip.js"
30
44
  },
@@ -32,7 +46,6 @@
32
46
  "async": "^3.2.6",
33
47
  "buffer-crc32": "^1.0.0",
34
48
  "is-stream": "^4.0.1",
35
- "lazystream": "^1.0.1",
36
49
  "normalize-path": "^3.0.0",
37
50
  "readable-stream": "^4.7.0",
38
51
  "readdir-glob": "^2.0.2",
@@ -42,11 +55,13 @@
42
55
  "devDependencies": {
43
56
  "archiver-jsdoc-theme": "1.1.3",
44
57
  "chai": "4.5.0",
58
+ "esbuild": "^0.27.3",
45
59
  "jsdoc": "4.0.4",
46
60
  "mkdirp": "3.0.1",
47
61
  "mocha": "10.8.2",
62
+ "npm-run-all": "^4.1.5",
48
63
  "prettier": "3.5.3",
49
- "rimraf": "5.0.10",
64
+ "rimraf": "^5.0.10",
50
65
  "stream-bench": "0.1.2",
51
66
  "tar": "6.2.1",
52
67
  "yauzl": "3.2.0"