|
|
|
@ -275,13 +275,20 @@ OgrFormat.prototype.sendResponse = function (opts, callback) {
|
|
|
|
|
var nextPipe = function (finish) {
|
|
|
|
|
logger.info({ custom: true, size: baking.req.length }, 'Sending responses');
|
|
|
|
|
var r = baking.req.shift();
|
|
|
|
|
if (!r) { finish(null); return; }
|
|
|
|
|
logger.info({ custom: true, size: baking.req.length }, 'Request shifted');
|
|
|
|
|
if (!r) {
|
|
|
|
|
logger.info({ custom: true, size: baking.req.length }, 'There is no request');
|
|
|
|
|
finish(null);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
logger.info({ custom: true, size: baking.req.length }, 'Sending file');
|
|
|
|
|
r.sendFile(err, dumpfile, function () {
|
|
|
|
|
nextPipe(finish);
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (!err) {
|
|
|
|
|
logger.info({ custom: true }, 'Next pipe');
|
|
|
|
|
nextPipe(this);
|
|
|
|
|
} else {
|
|
|
|
|
_.each(baking.req, function (r) {
|
|
|
|
@ -330,11 +337,13 @@ function ExportRequest (ostream, callback, beforeSink) {
|
|
|
|
|
|
|
|
|
|
ExportRequest.prototype.sendFile = function (err, filename, callback) {
|
|
|
|
|
if (err) {
|
|
|
|
|
logger.info({ custom: true }, 'There is an error sending file');
|
|
|
|
|
return callback(err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var that = this;
|
|
|
|
|
if (!this.canceled) {
|
|
|
|
|
logger.info({ custom: true }, 'Not cancelled (sending file)');
|
|
|
|
|
this.istream = fs.createReadStream(filename)
|
|
|
|
|
.on('open', function (/* fd */) {
|
|
|
|
|
if (that.beforeSink) {
|
|
|
|
@ -343,21 +352,25 @@ ExportRequest.prototype.sendFile = function (err, filename, callback) {
|
|
|
|
|
that.istream
|
|
|
|
|
.pipe(that.ostream)
|
|
|
|
|
.on('end', () => {
|
|
|
|
|
logger.info({ custom: true }, 'Sending file: on open end');
|
|
|
|
|
callback();
|
|
|
|
|
that.cb();
|
|
|
|
|
})
|
|
|
|
|
.on('error', (err) => {
|
|
|
|
|
logger.info({ custom: true }, 'Sending file: on open error');
|
|
|
|
|
callback();
|
|
|
|
|
that.cb(err);
|
|
|
|
|
});
|
|
|
|
|
})
|
|
|
|
|
.on('error', function (e) {
|
|
|
|
|
logger.info({ custom: true }, 'Sending file: on error');
|
|
|
|
|
console.log("Can't send response: " + e);
|
|
|
|
|
that.ostream.end();
|
|
|
|
|
that.cb(e);
|
|
|
|
|
callback();
|
|
|
|
|
})
|
|
|
|
|
.on('end', () => {
|
|
|
|
|
logger.info({ custom: true }, 'Sending file: on end');
|
|
|
|
|
that.cb();
|
|
|
|
|
callback();
|
|
|
|
|
});
|
|
|
|
|