archiver-zip-encrypted
archiver-zip-encrypted copied to clipboard
Support typescript
Archiver supports typescript with @types/archiver , but this plugin doesn't seem to support typescript.
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;
}
}
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?
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; } }
Hello, can you give me an example of how to use it? Thank you very much
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 } });
}