From 64138e36f3c139a879399b14328eefed999a9c30 Mon Sep 17 00:00:00 2001 From: Dave Lee Date: Wed, 23 May 2018 10:06:21 -0400 Subject: [PATCH 1/2] fix stream support in jszip typings, as the library supports this --- types/jszip/index.d.ts | 3 ++- types/jszip/jszip-tests.ts | 13 +++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/types/jszip/index.d.ts b/types/jszip/index.d.ts index bca2b6899c..ba3ea392c9 100644 --- a/types/jszip/index.d.ts +++ b/types/jszip/index.d.ts @@ -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; diff --git a/types/jszip/jszip-tests.ts b/types/jszip/jszip-tests.ts index 5d332a8070..d634767d58 100644 --- a/types/jszip/jszip-tests.ts +++ b/types/jszip/jszip-tests.ts @@ -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 string") { + 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); }); } From 8c4b85f862cdb722f13caa1de06299244d29e5ac Mon Sep 17 00:00:00 2001 From: Dave Date: Wed, 23 May 2018 10:28:51 -0400 Subject: [PATCH 2/2] Update jszip-tests.ts --- types/jszip/jszip-tests.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/jszip/jszip-tests.ts b/types/jszip/jszip-tests.ts index d634767d58..2910b5f729 100644 --- a/types/jszip/jszip-tests.ts +++ b/types/jszip/jszip-tests.ts @@ -112,7 +112,7 @@ function testJSZip() { }).catch((e: any) => log(SEVERITY.ERROR, e)); newJszip.file("stream.txt").async('text').then((text: string) => { - if (text === "test string") { + if (text === "test stream") { log(SEVERITY.INFO, "all ok"); } else { log(SEVERITY.ERROR, "no matching file found");