Files
docx-js/src/export/packer/buffer-stream.ts

29 lines
594 B
TypeScript
Raw Normal View History

2018-07-01 02:16:11 +01:00
import { Writable } from "stream";
export class BufferStream extends Writable {
2018-08-07 01:38:15 +01:00
private readonly data: Buffer[];
2018-07-01 02:16:11 +01:00
constructor() {
super();
this.data = [];
}
// tslint:disable-next-line:no-any
2018-08-07 01:38:15 +01:00
public _write(chunk: any, _: string, next: (err?: Error) => void): void {
2018-07-01 02:16:11 +01:00
this.data.push(Buffer.from(chunk));
next();
}
// tslint:disable-next-line:ban-types
public end(cb?: Function): void {
super.end(cb);
this.emit("close");
}
public get Buffer(): Buffer {
return Buffer.concat(this.data);
}
}