@@ -18,6 +18,7 @@ import * as fs from 'fs';
1818import { XmlHelper } from './helper/xml-helper' ;
1919import ModifyPresentationHelper from './helper/modify-presentation-helper' ;
2020import { ContentTracker } from './helper/content-tracker' ;
21+ import JSZip , { OutputType } from 'jszip' ;
2122
2223/**
2324 * Automizer
@@ -295,9 +296,7 @@ export default class Automizer implements IPresentationProps {
295296 * @returns summary object.
296297 */
297298 public async write ( location : string ) : Promise < AutomizerSummary > {
298- await this . writeSlides ( ) ;
299- await this . normalizePresentation ( ) ;
300- await this . applyModifyPresentationCallbacks ( ) ;
299+ await this . finalizePresentation ( ) ;
301300
302301 await this . rootTemplate . archive . output (
303302 this . getLocation ( location , 'output' ) ,
@@ -318,6 +317,43 @@ export default class Automizer implements IPresentationProps {
318317 } ;
319318 }
320319
320+ /**
321+ * Create a ReadableStream from output pptx file.
322+ * @param generatorOptions - JSZipGeneratorOptions for nodebuffer Output type
323+ * @returns Promise<NodeJS.ReadableStream>
324+ */
325+ public async stream (
326+ generatorOptions ?: JSZip . JSZipGeneratorOptions < 'nodebuffer' > ,
327+ ) : Promise < NodeJS . ReadableStream > {
328+ await this . finalizePresentation ( ) ;
329+
330+ if ( ! this . rootTemplate . archive . stream ) {
331+ throw 'Streaming is not implemented for current archive type' ;
332+ }
333+
334+ return this . rootTemplate . archive . stream ( this . params , generatorOptions ) ;
335+ }
336+
337+ /**
338+ * Pass final JSZip instance.
339+ * @returns Promise<NodeJS.ReadableStream>
340+ */
341+ public async getJSZip ( ) : Promise < JSZip > {
342+ await this . finalizePresentation ( ) ;
343+
344+ if ( ! this . rootTemplate . archive . getFinalArchive ) {
345+ throw 'GetFinalArchive is not implemented for current archive type' ;
346+ }
347+
348+ return this . rootTemplate . archive . getFinalArchive ( ) ;
349+ }
350+
351+ async finalizePresentation ( ) {
352+ await this . writeSlides ( ) ;
353+ await this . normalizePresentation ( ) ;
354+ await this . applyModifyPresentationCallbacks ( ) ;
355+ }
356+
321357 /**
322358 * Write all slides to archive.
323359 */
0 commit comments