From 4b90e1800be3755a2caadbd0fd2ed996c5e8a9cd Mon Sep 17 00:00:00 2001 From: Dolan Miu Date: Thu, 31 Mar 2016 19:28:12 +0100 Subject: [PATCH] added express packer --- ts/export/packer/express.ts | 21 +++++++++++++++++++++ ts/export/packer/packer.ts | 9 ++++++--- 2 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 ts/export/packer/express.ts diff --git a/ts/export/packer/express.ts b/ts/export/packer/express.ts new file mode 100644 index 0000000000..20a25cd843 --- /dev/null +++ b/ts/export/packer/express.ts @@ -0,0 +1,21 @@ +import {Packer} from "./packer"; +import * as fs from "fs"; +import * as express from "express"; + +export class ExpressPacker extends Packer { + private res: express.Response; + + constructor(res: express.Response) { + super(); + this.res = res; + + this.res.on('close', () => { + return res.status(200).send('OK').end(); + }); + } + + pack() { + this.res.attachment(name + ".docx"); + super.pack(this.res); + } +} \ No newline at end of file diff --git a/ts/export/packer/packer.ts b/ts/export/packer/packer.ts index a2675b57d6..d3bf55211f 100644 --- a/ts/export/packer/packer.ts +++ b/ts/export/packer/packer.ts @@ -1,10 +1,13 @@ import * as archiver from "archiver"; -import * as fs from 'fs'; +import * as fs from "fs"; +import {Formatter} from "../formatter"; -export class Packer { +export abstract class Packer { protected archive: any; + private formatter: Formatter; constructor() { + this.formatter = new Formatter(); this.archive = archiver.create("zip", {}); this.archive.on('error', (err) => { @@ -12,7 +15,7 @@ export class Packer { }); } - pack(output: fs.WriteStream): void { + pack(output: any): void { this.archive.pipe(output); this.archive.bulk([