Merge pull request #25965 from dlee-nvisia/master

fix stream support in jszip typings, as the library supports this
This commit is contained in:
Daniel Rosenwasser
2018-05-23 08:45:25 -07:00
committed by GitHub
2 changed files with 15 additions and 1 deletions

View File

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

View File

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