Skip to content

Commit

Permalink
Buf Fix #2093: the broken should be prior to file attachment feature …
Browse files Browse the repository at this point in the history
…introduced
  • Loading branch information
whowillcare committed Oct 11, 2019
1 parent 77f8b76 commit f53c624
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions models/export.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,18 @@ if (Meteor.isServer) {
});
}

// exporter maybe is broken since Gridfs introduced, add fs and path

export class Exporter {
constructor(boardId) {
this._boardId = boardId;
}

build() {
const fs = Npm.require('fs');
const os = Npm.require('os');
const path = Npm.require('path');

const byBoard = { boardId: this._boardId };
const byBoardNoLinked = {
boardId: this._boardId,
Expand Down Expand Up @@ -134,6 +140,9 @@ export class Exporter {
const getBase64Data = function(doc, callback) {
let buffer = new Buffer(0);
// callback has the form function (err, res) {}
const tmpWriteable = fs.createWriteStream(
path.join(os.tmpdir(), `tmpexport${process.pid}`),
);
const readStream = doc.createReadStream();
readStream.on('data', function(chunk) {
buffer = Buffer.concat([buffer, chunk]);
Expand All @@ -145,6 +154,7 @@ export class Exporter {
// done
callback(null, buffer.toString('base64'));
});
readStream.pipe(tmpWriteable);
};
const getBase64DataSync = Meteor.wrapAsync(getBase64Data);
result.attachments = Attachments.find(byBoard)
Expand Down

0 comments on commit f53c624

Please sign in to comment.