{"version":3,"sources":["src/CreateResult.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;;;;;;;AAEb,yBAAyB;AACzB,mCAA0C;AAE1C;;;;;GAKG;AACH;IAEE;;;;;;;;;;OAUG;IACK,MAAM,CAAO,SAAS,CAAC,QAAgB,EAAE,IAAY;;YAC3D,MAAM,CAAC,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM;gBACvC,EAAE,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC,GAAG;oBAC/B,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC,GAAG,OAAO,EAAE,CAAC;gBAChC,CAAC,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;QACL,CAAC;KAAA;IAWD;;;;;OAKG;IACH,YAAmB,IAAY;QAC7B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;IAED;;;;;;OAMG;IACI,QAAQ;QACb,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;IAED;;;;;;OAMG;IACI,QAAQ;QACb,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IAC1C,CAAC;IAED;;;;;;OAMG;IACI,QAAQ;QACb,MAAM,MAAM,GAAG,IAAI,iBAAQ,EAAE,CAAC;QAC9B,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;QACjC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAClB,MAAM,CAAC,MAAM,CAAC;IAChB,CAAC;IAED;;;;;;;OAOG;IACU,MAAM,CAAC,QAAgB;;YAClC,MAAM,YAAY,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;QAC1D,CAAC;KAAA;CAEF;AAxFD,oCAwFC","file":"CreateResult.js","sourcesContent":["'use strict';\n\nimport * as fs from 'fs';\nimport { Readable, Stream } from 'stream';\n\n/**\n * Allows exporting of PDF data to multiple formats.\n *\n * @export\n * @class CreateResult\n */\nexport class CreateResult {\n\n /**\n * Writes the given data Buffer to the specified file location.\n *\n * @private\n * @static\n * @param {string} filename the file name to write to.\n * @param {Buffer} data the data to write.\n * @returns {Promise}\n *\n * @memberof CreateResult\n */\n private static async writeFile(filename: string, data: Buffer): Promise {\n return new Promise((resolve, reject) => {\n fs.writeFile(filename, data, (err) => {\n err ? reject(err) : resolve();\n });\n });\n }\n\n /**\n * Base64-encoded PDF data.\n *\n * @private\n * @type {string}\n * @memberof CreateResult\n */\n private data: string;\n\n /**\n * Creates an instance of CreateResult.\n * @param {string} data base64 PDF data\n *\n * @memberof CreateResult\n */\n public constructor(data: string) {\n this.data = data;\n }\n\n /**\n * Get the base64 PDF data.\n *\n * @returns {string} base64 PDF data.\n *\n * @memberof CreateResult\n */\n public toBase64(): string {\n return this.data;\n }\n\n /**\n * Get a Buffer of the PDF data.\n *\n * @returns {Buffer} PDF data.\n *\n * @memberof CreateResult\n */\n public toBuffer(): Buffer {\n return Buffer.from(this.data, 'base64');\n }\n\n /**\n * Get a Stream of the PDF data.\n *\n * @returns {Stream} Stream of PDF data.\n *\n * @memberof CreateResult\n */\n public toStream(): Stream {\n const stream = new Readable();\n stream.push(this.data, 'base64');\n stream.push(null);\n return stream;\n }\n\n /**\n * Saves the PDF to a file.\n *\n * @param {string} filename the filename.\n * @returns {Promise} resolves upon successful create.\n *\n * @memberof CreateResult\n */\n public async toFile(filename: string): Promise {\n await CreateResult.writeFile(filename, this.toBuffer());\n }\n\n}\n"],"sourceRoot":"../.."}