From 1ee58c511495db1b41ecdc04e3f1df1948c41c06 Mon Sep 17 00:00:00 2001 From: Dolan Date: Tue, 2 May 2017 01:08:44 +0100 Subject: [PATCH] Archiver update from 0.15.0 to 1.3.x (#15894) * archiver clean up and updated version * added tslint.json * added back in create because it still works. Updated examples * fixed listing issues * fixed more linting issues * added glob options and EntryData * added more to tests * fixed tests by returning this, instead of void * removed whitespace * Add node types import * Keep original author --- types/archiver/archiver-tests.ts | 30 +++++++++++++++-------- types/archiver/index.d.ts | 42 ++++++++++++++++++++++---------- 2 files changed, 49 insertions(+), 23 deletions(-) diff --git a/types/archiver/archiver-tests.ts b/types/archiver/archiver-tests.ts index 57a569ab02..d4ea423a4f 100644 --- a/types/archiver/archiver-tests.ts +++ b/types/archiver/archiver-tests.ts @@ -1,26 +1,36 @@ -import Archiver = require('archiver'); -import FS = require('fs'); +import * as Archiver from 'archiver'; +import * as fs from 'fs'; const archiver = Archiver.create('zip'); -const writeStream = FS.createWriteStream('./archiver.d.ts'); -const readStream = FS.createReadStream('./archiver.d.ts'); +const writeStream = fs.createWriteStream('./archiver.d.ts'); +const readStream = fs.createReadStream('./archiver.d.ts'); archiver.abort(); + +archiver.pipe(writeStream); +archiver.append(readStream, { name: 'archiver.d.ts' }); + archiver.append(readStream, {name: 'archiver.d.ts'}) .append(readStream, {name: 'archiver.d.ts'}); archiver.bulk({ mappaing: {} }); archiver.directory('./path', './someOtherPath'); -archiver.directory('./path', { name: "testName"} ); - +archiver.directory('./path', { name: "testName" }); archiver.directory('./', "", {}); -archiver.directory('./', {name: 'test'}, {}); +archiver.directory('./', { name: 'test' }, {}); + +archiver.append(readStream, { + name: "sub/folder.xml" +}); + +archiver.glob("**", { + cwd: 'path/to/files', +}); +archiver.glob('./path', {}, {}); archiver.file('./path', { name: 'test' }); -archiver.glob('./path', {}, {}); -archiver.finalize(); archiver.setFormat('zip'); archiver.setModule(() => {}); @@ -28,4 +38,4 @@ archiver.setModule(() => {}); archiver.pointer(); archiver.use(() => {}); -archiver.pipe(writeStream); +archiver.finalize(); diff --git a/types/archiver/index.d.ts b/types/archiver/index.d.ts index 9c2b2ae509..2e4b1063ff 100644 --- a/types/archiver/index.d.ts +++ b/types/archiver/index.d.ts @@ -1,51 +1,67 @@ // Type definitions for archiver 1.3 // Project: https://github.com/archiverjs/node-archiver -// Definitions by: Esri +// Definitions by: Esri , Dolan Miu // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped /* =================== USAGE =================== import Archiver = require('archiver); var archiver = Archiver.create('zip'); - archiver.pipe(FS.createWriteStream('xxx')); - archiver.append(FS.createReadStream('xxx')); + archiver.pipe(fs.createWriteStream('xxx')); + archiver.append(fs.createReadStream('xxx')); archiver.finalize(); =============================================== */ /// -import * as FS from 'fs'; -import * as STREAM from 'stream'; +import * as fs from 'fs'; +import * as stream from 'stream'; +import * as express from 'express'; +import * as glob from 'glob'; -declare function archiver(format: string, options?: {}): archiver.Archiver; +declare function archiver(format: archiver.Format, options?: archiver.ArchiverOptions): archiver.Archiver; declare namespace archiver { - function create(format: string, options?: {}): Archiver; + type Format = 'zip' | 'tar'; + + function create(format: string, options?: ArchiverOptions): Archiver; function registerFormat(format: string, module: Function): void; - interface nameInterface { + interface EntryData { name?: string; + prefix?: string; + stats?: string; } - interface Archiver extends STREAM.Transform { + interface Archiver extends stream.Transform { abort(): this; - append(source: STREAM.Readable | Buffer | string, name: nameInterface): this; + append(source: stream.Readable | Buffer | string, name?: EntryData): this; bulk(mappings: any): this; - directory(dirpath: string, destpath: nameInterface | string, data?: any | Function): this; + directory(dirpath: string, options: EntryData | string, data?: EntryData): this; - file(filepath: string, data: any): this; - glob(pattern: string, options: {}, data: any): this; + file(filename: string, data: EntryData): this; + glob(pattern: string, options?: glob.IOptions, data?: EntryData): this; finalize(): this; + pipe(stream: fs.WriteStream | express.Response): void; + setFormat(format: string): this; setModule(module: Function): this; pointer(): number; use(plugin: Function): this; } + + interface ArchiverOptions { + store?: boolean; + gzip?: boolean; + gzipOptions?: { + level: number, + }; + } } export = archiver;