Add ArchiverError, some explicit handlers

This commit is contained in:
Dave Lee
2018-06-29 11:33:46 -05:00
parent a5b0278214
commit 1ebb489ba7
2 changed files with 36 additions and 0 deletions
+12
View File
@@ -67,3 +67,15 @@ archiver.use(() => {});
archiver.finalize();
archiver.symlink('./path', './target');
function fakeHandler(err: Archiver.ArchiverError) {
console.log(err.code);
console.log(err.message);
console.log(err.stack);
console.log(err.data);
}
const fakeError = new Archiver.ArchiverError('code', 'foo');
archiver.on('error', fakeHandler);
archiver.on('warning', fakeHandler);
+24
View File
@@ -24,9 +24,26 @@ declare namespace archiver {
mode?: number;
}
interface ProgressData {
entries: {
total: number;
processed: number;
};
fs: {
totalBytes: number;
processedBytes: number;
};
}
/** 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) */
type EntryDataFunction = (entry: EntryData) => false | EntryData;
class ArchiverError extends Error {
code: string; // Since archiver format support is modular, we cannot enumerate all possible error codes, as the modules can throw arbitrary ones.
data: any;
constructor(code: string, data: any);
}
interface Archiver extends stream.Transform {
abort(): this;
append(source: stream.Readable | Buffer | string, name?: EntryData): this;
@@ -44,6 +61,13 @@ declare namespace archiver {
use(plugin: Function): this;
symlink(filepath: string, target: string): this;
on(event: 'error' | 'warning', listener: (error: ArchiverError) => void): this;
on(event: 'data', listener: (data: EntryData) => void): this;
on(event: 'progress', listener: (progress: ProgressData) => void): this;
on(event: 'close' | 'drain' | 'finish', listener: () => void): this;
on(event: 'pipe' | 'unpipe', listener: (src: stream.Readable) => void): this;
on(event: string, listener: (...args: any[]) => void): this;
}
type ArchiverOptions = CoreOptions & TransformOptions & ZipOptions & TarOptions;