add type yazl

This commit is contained in:
taoqf
2018-03-19 14:40:00 +08:00
parent 17c3e0a996
commit 49f613d038
4 changed files with 92 additions and 0 deletions

46
types/yazl/index.d.ts vendored Normal file
View File

@@ -0,0 +1,46 @@
// Type definitions for yazl 2.4
// Project: https://github.com/thejoshwolfe/yazl
// Definitions by: taoqf <https://github.com/taoqf>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.1
/// <reference types="node" />
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<Options>): void;
outputStream: Writable;
addReadStream(input: Readable, metadataPath: string, options?: Partial<ReadStreamOptions>): void;
addBuffer(buffer: Buffer, metadataPath: string, options?: Partial<Options>): void;
end(optoins?: EndOptions, finalSizeCallback?: () => void): void;
addEmptyDirectory(metadataPath: string, options?: Partial<DirectoryOptions>): void;
dateToDosDateTime(jsDate: Date): DosDateTime;
}

23
types/yazl/tsconfig.json Normal file
View File

@@ -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"
]
}

1
types/yazl/tslint.json Normal file
View File

@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }

22
types/yazl/yazl-tests.ts Normal file
View File

@@ -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();