Crash on exporting packet #104

This commit is contained in:
Bryan Ashby 2017-03-01 20:02:45 -07:00
parent 02d76f5573
commit be38bbf3c7
2 changed files with 17 additions and 17 deletions

View File

@ -930,8 +930,12 @@ Packet.prototype.writeMessageEntry = function(ws, msgEntry) {
}; };
Packet.prototype.writeTerminator = function(ws) { Packet.prototype.writeTerminator = function(ws) {
ws.write(new Buffer( [ 0 ] )); // final extra null term //
return 1; // From FTS-0001.016:
// "A pseudo-message beginning with the word 0000H signifies the end of the packet."
//
ws.write(new Buffer( [ 0x00, 0x00 ] )); // final extra null term
return 2;
}; };
Packet.prototype.writeStream = function(ws, messages, options) { Packet.prototype.writeStream = function(ws, messages, options) {

View File

@ -527,6 +527,14 @@ function FTNMessageScanTossModule() {
let remainMessageId; let remainMessageId;
const createTempPacket = !_.isString(exportOpts.nodeConfig.archiveType) || 0 === exportOpts.nodeConfig.archiveType.length; const createTempPacket = !_.isString(exportOpts.nodeConfig.archiveType) || 0 === exportOpts.nodeConfig.archiveType.length;
function finalizePacket(cb) {
packet.writeTerminator(ws);
ws.end();
ws.once('finish', () => {
return cb(null);
});
}
async.each(messageUuids, (msgUuid, nextUuid) => { async.each(messageUuids, (msgUuid, nextUuid) => {
let message = new Message(); let message = new Message();
@ -534,11 +542,7 @@ function FTNMessageScanTossModule() {
[ [
function finalizePrevious(callback) { function finalizePrevious(callback) {
if(packet && currPacketSize >= self.moduleConfig.packetTargetByteSize) { if(packet && currPacketSize >= self.moduleConfig.packetTargetByteSize) {
packet.writeTerminator(ws); return finalizePacket(callback);
ws.end();
ws.once('finish', () => {
callback(null);
});
} else { } else {
callback(null); callback(null);
} }
@ -633,11 +637,7 @@ function FTNMessageScanTossModule() {
[ [
function terminateLast(callback) { function terminateLast(callback) {
if(packet) { if(packet) {
packet.writeTerminator(ws); return finalizePacket(callback);
ws.end();
ws.once('finish', () => {
callback(null);
});
} else { } else {
callback(null); callback(null);
} }
@ -668,11 +668,7 @@ function FTNMessageScanTossModule() {
packet.writeHeader(ws, packetHeader); packet.writeHeader(ws, packetHeader);
ws.write(remainMessageBuf); ws.write(remainMessageBuf);
packet.writeTerminator(ws); return finalizePacket(callback);
ws.end();
ws.once('finish', () => {
callback(null);
});
} else { } else {
callback(null); callback(null);
} }