archiver-zip-encrypted icon indicating copy to clipboard operation
archiver-zip-encrypted copied to clipboard

Support typescript

Open alalialisiong opened this issue 2 years ago • 6 comments

Archiver supports typescript with @types/archiver , but this plugin doesn't seem to support typescript.

alalialisiong avatar Mar 22 '22 07:03 alalialisiong

At the moment, I use the following in my project's types/archiver.d.ts:

import 'archiver';

// add typescript support for archiver-zip-encrypted
// https://github.com/artem-karpenko/archiver-zip-encrypted
declare module 'archiver' {
    interface CoreOptions {
        encryptionMethod: 'aes256' | 'zip20' | undefined;
        password: string | undefined;
    }
}

ypicard avatar May 25 '22 13:05 ypicard

At the moment, I use the following in my project's types/archiver.d.ts:

import 'archiver';

// add typescript support for archiver-zip-encrypted
// https://github.com/artem-karpenko/archiver-zip-encrypted
declare module 'archiver' {
    interface CoreOptions {
        encryptionMethod: 'aes256' | 'zip20' | undefined;
        password: string | undefined;
    }
}

Any way of doing this without lossing existing CoreOptions?

zeeh1975 avatar Nov 07 '23 16:11 zeeh1975

import 'archiver';

// add typescript support for archiver-zip-encrypted // https://github.com/artem-karpenko/archiver-zip-encrypted declare module 'archiver' { interface CoreOptions { encryptionMethod: 'aes256' | 'zip20' | undefined; password: string | undefined; } }

Making them optionals do the trick

import 'archiver';

// add typescript support for archiver-zip-encrypted // https://github.com/artem-karpenko/archiver-zip-encrypted declare module 'archiver' { interface CoreOptions { encryptionMethod?: 'aes256' | 'zip20' | undefined; password?: string | undefined; } }

zeeh1975 avatar Nov 07 '23 17:11 zeeh1975

Hello, can you give me an example of how to use it? Thank you very much

aestcar avatar Jan 04 '24 06:01 aestcar

Hello, can you give me an example of how to use it? Thank you very much

About the file you should put it anywhere inside your proyect, in particular y put it in source/types You can name it as you want but the extension should be .d.ts Then you can use zip-encrypted when you create an archive:

const compressionLevel = 5;
const encryptionMethod = ZipEncryptionMethod.ZIP20;
let archive: archiver.Archiver;
if (password !== "") { // you cannot use zip-encrypted without a password
            archive = archiver.create("zip-encrypted", { zlib: { level: compressionLevel }, encryptionMethod: encryptionMethod, password: password });
        } else {
            archive = archiver.create("zip", { zlib: { level: compressionLevel } });
        }

zeeh1975 avatar Feb 08 '24 13:02 zeeh1975