Skip to content

Commit

Permalink
feat(retr): emit connection event on success/failure
Browse files Browse the repository at this point in the history
  • Loading branch information
trs committed Feb 10, 2018
1 parent c606069 commit 6020409
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/commands/registration/retr.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ module.exports = {
if (!this.fs) return this.reply(550, 'File system not instantiated');
if (!this.fs.read) return this.reply(402, 'Not supported by file system');

const filePath = command.arg;

return this.connector.waitForConnection()
.tap(() => this.commandSocket.pause())
.then(() => Promise.resolve(this.fs.read(command.arg, {start: this.restByteCount})))
.then(() => Promise.resolve(this.fs.read(filePath, {start: this.restByteCount})))
.then(stream => {
const destroyConnection = (connection, reject) => err => {
if (connection) connection.destroy(err);
Expand All @@ -32,6 +34,7 @@ module.exports = {

return this.reply(150).then(() => stream.resume() && this.connector.socket.resume())
.then(() => eventsPromise)
.tap(() => this.emit('RETR', null, filePath))
.finally(() => stream.destroy && stream.destroy());
})
.then(() => this.reply(226))
Expand All @@ -41,6 +44,7 @@ module.exports = {
})
.catch(err => {
log.error(err);
this.emit('RETR', err);
return this.reply(551, err.message);
})
.finally(() => {
Expand Down

0 comments on commit 6020409

Please sign in to comment.