From be38bbf3c739fadcd29f597550a4ef73147a149a Mon Sep 17 00:00:00 2001 From: Bryan Ashby Date: Wed, 1 Mar 2017 20:02:45 -0700 Subject: [PATCH] Crash on exporting packet #104 --- core/ftn_mail_packet.js | 8 ++++++-- core/scanner_tossers/ftn_bso.js | 26 +++++++++++--------------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/core/ftn_mail_packet.js b/core/ftn_mail_packet.js index 324f08ed..86609d5b 100644 --- a/core/ftn_mail_packet.js +++ b/core/ftn_mail_packet.js @@ -930,8 +930,12 @@ Packet.prototype.writeMessageEntry = function(ws, msgEntry) { }; 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) { diff --git a/core/scanner_tossers/ftn_bso.js b/core/scanner_tossers/ftn_bso.js index e4add699..d7734826 100644 --- a/core/scanner_tossers/ftn_bso.js +++ b/core/scanner_tossers/ftn_bso.js @@ -526,6 +526,14 @@ function FTNMessageScanTossModule() { let remainMessageBuf; let remainMessageId; 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) => { let message = new Message(); @@ -534,11 +542,7 @@ function FTNMessageScanTossModule() { [ function finalizePrevious(callback) { if(packet && currPacketSize >= self.moduleConfig.packetTargetByteSize) { - packet.writeTerminator(ws); - ws.end(); - ws.once('finish', () => { - callback(null); - }); + return finalizePacket(callback); } else { callback(null); } @@ -633,11 +637,7 @@ function FTNMessageScanTossModule() { [ function terminateLast(callback) { if(packet) { - packet.writeTerminator(ws); - ws.end(); - ws.once('finish', () => { - callback(null); - }); + return finalizePacket(callback); } else { callback(null); } @@ -668,11 +668,7 @@ function FTNMessageScanTossModule() { packet.writeHeader(ws, packetHeader); ws.write(remainMessageBuf); - packet.writeTerminator(ws); - ws.end(); - ws.once('finish', () => { - callback(null); - }); + return finalizePacket(callback); } else { callback(null); }