added express packer
This commit is contained in:
21
ts/export/packer/express.ts
Normal file
21
ts/export/packer/express.ts
Normal file
@ -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);
|
||||||
|
}
|
||||||
|
}
|
@ -1,10 +1,13 @@
|
|||||||
import * as archiver from "archiver";
|
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;
|
protected archive: any;
|
||||||
|
private formatter: Formatter;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
|
this.formatter = new Formatter();
|
||||||
this.archive = archiver.create("zip", {});
|
this.archive = archiver.create("zip", {});
|
||||||
|
|
||||||
this.archive.on('error', (err) => {
|
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.pipe(output);
|
||||||
|
|
||||||
this.archive.bulk([
|
this.archive.bulk([
|
||||||
|
Reference in New Issue
Block a user