Add Express packer deprecation warning
This commit is contained in:
@ -32,21 +32,32 @@ const docx = require("docx");
|
|||||||
|
|
||||||
const doc = new docx.Document();
|
const doc = new docx.Document();
|
||||||
const exporter = new docx.StreamPacker(doc);
|
const exporter = new docx.StreamPacker(doc);
|
||||||
const buffer = exporter.pack();
|
const stream = exporter.pack();
|
||||||
```
|
```
|
||||||
|
|
||||||
## Express Packer
|
## Express Packer
|
||||||
|
|
||||||
|
The old express packer is now deprecated and may disappear soon, so you should upgrade.
|
||||||
|
|
||||||
|
The reason for this is because it means this project needs to know about and use `express`, which for a Word document generator, does not sound right. Seperation of concerns.
|
||||||
|
|
||||||
|
It will still be usable (for now), but it is ill advised.
|
||||||
|
|
||||||
I used the express exporter in my [website](http://www.dolan.bio).
|
I used the express exporter in my [website](http://www.dolan.bio).
|
||||||
|
|
||||||
Pass in the necessary parameters:
|
The recommended way is to use the `StreamPacker` and handle the `express` magic outside of the library:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const docx = require("docx");
|
const docx = require("docx");
|
||||||
|
|
||||||
const doc = new docx.Document();
|
const doc = new docx.Document();
|
||||||
const exporter = new docx.ExpressPacker(doc, res);
|
const exporter = new docx.StreamPacker(doc);
|
||||||
exporter.pack("My Document");
|
|
||||||
|
const stream = exporter.pack();
|
||||||
|
|
||||||
|
// Express' response object
|
||||||
|
res.attachment('yourfile.xlsx');
|
||||||
|
stream.pipe(res);
|
||||||
```
|
```
|
||||||
|
|
||||||
where `res` is the response object obtained through the Express router. It is that simple. The file will begin downloading in the browser.
|
where `res` is the response object obtained through the Express router. It is that simple. The file will begin downloading in the browser.
|
||||||
|
@ -4,6 +4,9 @@ import { File } from "file";
|
|||||||
import { Compiler } from "./compiler";
|
import { Compiler } from "./compiler";
|
||||||
import { IPacker } from "./packer";
|
import { IPacker } from "./packer";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated ExpressPacker is now deprecated. Please use the StreamPacker instead and pipe that to `express`' `res` object
|
||||||
|
*/
|
||||||
export class ExpressPacker implements IPacker {
|
export class ExpressPacker implements IPacker {
|
||||||
private readonly packer: Compiler;
|
private readonly packer: Compiler;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user