mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-06-01 19:45:48 +08:00
Merge pull request #25965 from dlee-nvisia/master
fix stream support in jszip typings, as the library supports this
This commit is contained in:
3
types/jszip/index.d.ts
vendored
3
types/jszip/index.d.ts
vendored
@@ -31,6 +31,7 @@ interface InputByType {
|
||||
uint8array: Uint8Array;
|
||||
arraybuffer: ArrayBuffer;
|
||||
blob: Blob;
|
||||
stream: NodeJS.ReadableStream;
|
||||
}
|
||||
|
||||
interface OutputByType {
|
||||
@@ -44,7 +45,7 @@ interface OutputByType {
|
||||
nodebuffer: Buffer;
|
||||
}
|
||||
|
||||
type InputFileFormat = InputByType[keyof InputByType] | NodeJS.ReadableStream;
|
||||
type InputFileFormat = InputByType[keyof InputByType];
|
||||
|
||||
declare namespace JSZip {
|
||||
type InputType = keyof InputByType;
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import JSZip = require('jszip');
|
||||
|
||||
import { Readable } from "stream";
|
||||
|
||||
const SEVERITY = {
|
||||
DEBUG: 0,
|
||||
INFO: 1,
|
||||
@@ -10,9 +12,12 @@ const SEVERITY = {
|
||||
|
||||
function createTestZip(): JSZip {
|
||||
const zip = new JSZip();
|
||||
const stream = new Readable();
|
||||
stream.push("test stream");
|
||||
zip.file("test.txt", "test string");
|
||||
zip.file("test", null, { dir: true });
|
||||
zip.file("test/test.txt", "test string");
|
||||
zip.file("stream.txt", stream);
|
||||
return zip;
|
||||
}
|
||||
|
||||
@@ -105,6 +110,14 @@ function testJSZip() {
|
||||
log(SEVERITY.ERROR, "wrong number of files");
|
||||
}
|
||||
}).catch((e: any) => log(SEVERITY.ERROR, e));
|
||||
|
||||
newJszip.file("stream.txt").async('text').then((text: string) => {
|
||||
if (text === "test stream") {
|
||||
log(SEVERITY.INFO, "all ok");
|
||||
} else {
|
||||
log(SEVERITY.ERROR, "no matching file found");
|
||||
}
|
||||
}).catch((e: any) => log(SEVERITY.ERROR, e));
|
||||
}).catch((e: any) => { console.error(e); });
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user