Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion lib/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,22 @@ Archiver.prototype.finalize = function() {
this._finalize();
}

return this;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return signature changes hence backward compatibility break

var self = this;

return new Promise(function(resolve, reject) {
var errored;

self._module.on('end', function() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lmk if close is better here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hum, that difference usually matters more for fs.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (!errored) {
resolve();
}
})

self._module.on('error', function(err) {
errored = true;
reject(err);
})
})
};

/**
Expand Down
19 changes: 19 additions & 0 deletions test/archiver.js
Original file line number Diff line number Diff line change
Expand Up @@ -361,5 +361,24 @@ describe('archiver', function() {
});
});

describe('#promise', function() {
var archive;

it('should use a promise', function(done) {
archive = archiver('json');
var testStream = new WriteStream('tmp/append.json');

archive.pipe(testStream);

archive
.append(testBuffer, { name: 'buffer.txt', date: testDate })
.append(fs.createReadStream('test/fixtures/test.txt'), { name: 'stream.txt', date: testDate })
.append(null, { name: 'directory/', date: testDate })
.finalize()
.then(function() {
done()
})
});
})
});
});