diff --git a/types/yazl/index.d.ts b/types/yazl/index.d.ts new file mode 100644 index 0000000000..45288eaad5 --- /dev/null +++ b/types/yazl/index.d.ts @@ -0,0 +1,46 @@ +// Type definitions for yazl 2.4 +// Project: https://github.com/thejoshwolfe/yazl +// Definitions by: taoqf +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.1 + +/// + +import { Readable, Writable } from 'stream'; +import { Buffer } from 'buffer'; + +export interface Options { + mtime: Date; + mode: number; + compress: boolean; + forceZip64Format: boolean; +} + +export interface ReadStreamOptions extends Options { + size: number; +} + +export interface DirectoryOptions { + mtime: Date; + mode: number; +} + +export interface EndOptions { + forceZip64Format: boolean; +} + +export interface DosDateTime { + date: number; + time: number; +} + +export class ZipFile { + addFile(realPath: string, metadataPath: string, options?: Partial): void; + outputStream: Writable; + addReadStream(input: Readable, metadataPath: string, options?: Partial): void; + addBuffer(buffer: Buffer, metadataPath: string, options?: Partial): void; + end(optoins?: EndOptions, finalSizeCallback?: () => void): void; + + addEmptyDirectory(metadataPath: string, options?: Partial): void; + dateToDosDateTime(jsDate: Date): DosDateTime; +} diff --git a/types/yazl/tsconfig.json b/types/yazl/tsconfig.json new file mode 100644 index 0000000000..124a83ec4d --- /dev/null +++ b/types/yazl/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "yazl-tests.ts" + ] +} diff --git a/types/yazl/tslint.json b/types/yazl/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/yazl/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } diff --git a/types/yazl/yazl-tests.ts b/types/yazl/yazl-tests.ts new file mode 100644 index 0000000000..dfc5cd3c27 --- /dev/null +++ b/types/yazl/yazl-tests.ts @@ -0,0 +1,22 @@ +import { ZipFile } from "yazl"; +import fs = require('fs'); + +const zipfile = new ZipFile(); +zipfile.addFile("file1.txt", "file1.txt"); +// (add only files, not directories) +zipfile.addFile("path/to/file.txt", "path/in/zipfile.txt"); +// pipe() can be called any time after the constructor +zipfile.outputStream.pipe(fs.createWriteStream("output.zip")).on("close", () => { + console.log("done"); +}); +// alternate apis for adding files: +zipfile.addReadStream(process.stdin, "stdin.txt", { + mtime: new Date(), + mode: parseInt("0100664", 8), // -rw-rw-r-- +}); +zipfile.addBuffer(new Buffer("hello"), "hello.txt", { + mtime: new Date(), + mode: parseInt("0100664", 8), // -rw-rw-r-- +}); +// call end() after all the files have been added +zipfile.end();