Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ jobs:
- name: npm install and test
run: |
npm ci
npm run typecheck
npm test
env:
CI: true
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## Changelog

**Unreleased**

- Bundle TypeScript declarations. `@types/archiver` is no longer required.

**8.0.0** - <small>_May 8, 2026_</small> — [Diff](https://github.com/archiverjs/node-archiver/compare/7.0.1...8.0.0)

**7.0.1** - <small>_March 9, 2024_</small> — [Diff](https://github.com/archiverjs/node-archiver/compare/7.0.0...7.0.1)
Expand Down
169 changes: 169 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
/**
* Type definitions for archiver 8.x
*
* archiver v8 exports the base `Archiver` class plus format-specific subclasses
* (`ZipArchive`, `TarArchive`, `JsonArchive`). Each subclass instance is a
* Node `stream.Transform`, so the standard Readable/Writable APIs are available.
*/

import { Stats } from "node:fs";
import {
Readable,
Transform,
TransformOptions as NodeTransformOptions,
} from "node:stream";
import { ZlibOptions } from "node:zlib";

export interface CoreOptions {
/** Number of workers used to process the internal fs stat queue. @default 4 */
statConcurrency?: number;
}

export type TransformOptions = NodeTransformOptions;

export interface ZipOptions {
/** Sets the zip archive comment. */
comment?: string;
/** Forces the archive to contain local file times instead of UTC. */
forceLocalTime?: boolean;
/** Forces the archive to contain ZIP64 headers. */
forceZip64?: boolean;
/** Prepends a forward slash to archive file paths. @default false */
namePrependSlash?: boolean;
/** Sets the compression method to STORE. @default false */
store?: boolean;
/** Options passed through to zlib. */
zlib?: ZlibOptions;
}

export interface TarOptions {
/** Compress the tar archive with gzip. @default false */
gzip?: boolean;
/** Options passed through to zlib when gzip is enabled. */
gzipOptions?: ZlibOptions;
}

export type ArchiverOptions = CoreOptions &
TransformOptions &
ZipOptions &
TarOptions;

export interface EntryData {
/** Entry name including internal path. */
name: string;
/** Entry modification date. */
date?: Date | string;
/** Entry permissions (octal as decimal). */
mode?: number;
/** Path prefix prepended to `name`. Useful with `directory` / `glob`. */
prefix?: string;
/** Pre-computed fs.Stats — avoids a redundant stat call. */
stats?: Stats;
}

export interface ZipEntryData extends EntryData {
/** Sets the compression method for this entry to STORE. */
store?: boolean;
}

export type TarEntryData = EntryData;

/** Return `false` to skip an entry, or an `EntryData` to mutate it. */
export type EntryDataFunction = (entry: EntryData) => false | EntryData;

export interface ProgressData {
entries: {
total: number;
processed: number;
};
fs: {
totalBytes: number;
processedBytes: number;
};
}

export interface GlobOptions {
cwd?: string;
/** Other readdir-glob options pass through. */
[key: string]: unknown;
}

/**
* Shape of errors emitted on the `error` and `warning` events. Not a runtime
* export — typed structurally so consumers can annotate listeners without
* importing a class that the package does not expose.
*/
export interface ArchiverError extends Error {
code: string;
data: unknown;
path?: string;
}

export class Archiver extends Transform {
constructor(options?: ArchiverOptions);

/**
* Aborts the archiving process. Pending queue tasks are dropped, active
* workers are allowed to finish, and the stream is ended.
*/
abort(): this;

/** Appends an input source (string, Buffer, or Readable) to the archive. */
append(
source: Readable | Buffer | string,
data?: EntryData | ZipEntryData | TarEntryData,
): this;

/**
* Appends a directory recursively. Pass `false` as `destpath` to flatten the
* directory contents to the archive root.
*/
directory(
dirpath: string,
destpath: false | string,
data?: Partial<EntryData> | EntryDataFunction,
): this;

/** Appends a single file by path, using lazystream to defer the fd open. */
file(filepath: string, data: EntryData): this;

/** Appends every file matching a readdir-glob pattern. */
glob(pattern: string, options?: GlobOptions, data?: Partial<EntryData>): this;

/** Finalizes the archive. Resolves once the underlying module emits `end`. */
finalize(): Promise<void>;

/**
* Programmatically adds a symlink entry. Does not touch the filesystem.
* `mode` defaults to the format-specific default if omitted.
*/
symlink(filepath: string, target: string, mode?: number): this;

/** Current number of bytes emitted by the stream. */
pointer(): number;

// Typed event listeners. Falls through to the base `Transform` overloads
// for everything else.
on(
event: "error" | "warning",
listener: (error: ArchiverError) => void,
): this;
on(event: "data", listener: (data: Buffer) => void): this;
on(event: "progress", listener: (progress: ProgressData) => void): this;
on(event: "entry", listener: (entry: EntryData) => void): this;
on(event: "close" | "drain" | "finish" | "end", listener: () => void): this;
on(event: "pipe" | "unpipe", listener: (src: Readable) => void): this;
on(event: string | symbol, listener: (...args: unknown[]) => void): this;
}

export class ZipArchive extends Archiver {
constructor(options?: CoreOptions & NodeTransformOptions & ZipOptions);
}

export class TarArchive extends Archiver {
constructor(options?: CoreOptions & NodeTransformOptions & TarOptions);
}

export class JsonArchive extends Archiver {
constructor(options?: CoreOptions & NodeTransformOptions);
}
58 changes: 56 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 11 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,24 @@
},
"license": "MIT",
"type": "module",
"exports": "./index.js",
"types": "./index.d.ts",
"exports": {
".": {
"types": "./index.d.ts",
"import": "./index.js"
}
},
"files": [
"index.js",
"index.d.ts",
"lib"
],
"engines": {
"node": ">=18"
},
"scripts": {
"test": "mocha --reporter dot",
"typecheck": "tsc --project tsconfig.json",
"bench": "node benchmark/simple/pack-zip.js"
},
"dependencies": {
Expand All @@ -40,6 +48,7 @@
"zip-stream": "^7.0.2"
},
"devDependencies": {
"@types/node": "22.10.5",
"archiver-jsdoc-theme": "1.1.3",
"chai": "6.2.2",
"jsdoc": "4.0.5",
Expand All @@ -49,6 +58,7 @@
"rimraf": "6.1.3",
"stream-bench": "0.1.2",
"tar": "6.2.1",
"typescript": "^6.0.3",
"yauzl": "3.3.0"
},
"keywords": [
Expand Down
Loading