Skip to content

Commit

Permalink
fix(import): remove usage of stream.finished
Browse files Browse the repository at this point in the history
- stream.finished wasn't added until node v10
  • Loading branch information
acburdine committed Nov 6, 2019
1 parent 7e1db00 commit e0d05c5
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions lib/tasks/import/api.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
const fs = require('fs-extra');
const got = require('got');
const get = require('lodash/get');
const util = require('util');
const stream = require('stream');
const semver = require('semver');
const FormData = require('form-data');
const {Cookie} = require('tough-cookie');

const finished = util.promisify(stream.finished);

const {SystemError} = require('../../errors');

const bases = {
Expand Down Expand Up @@ -103,10 +99,12 @@ async function runImport(version, url, auth, exportFile) {
async function downloadExport(version, url, auth, outputFile) {
const authOpts = await getAuthOpts(version, url, auth);

const ws = fs.createWriteStream(outputFile);
const resp = got.stream('/db/', {...authOpts}).pipe(ws);
await new Promise((resolve, reject) => {
const ws = fs.createWriteStream(outputFile);
const resp = got.stream('/db/', {...authOpts}).pipe(ws);

await finished(resp);
resp.on('finish', () => resolve()).on('error', reject);
});
}

module.exports = {
Expand Down

0 comments on commit e0d05c5

Please sign in to comment.