fix downloadApp

This commit is contained in:
Jonah Stiennon
2015-08-27 14:37:11 -07:00
parent 7120f4c75d
commit 42824d98e3
2 changed files with 16 additions and 4 deletions
+14 -3
View File
@@ -7,7 +7,7 @@ import B from 'bluebird';
import { tempDir, system, fs } from 'appium-support';
import { exec } from 'teen_process';
import AdmZip from 'adm-zip';
import request from 'request-promise';
import requestWithoutPromises from 'request';
const ZIP_EXTS = ['.zip', '.ipa'];
@@ -57,13 +57,24 @@ async function downloadApp (app, appExt) {
}
async function downloadFile (fileUrl, suffix) {
// We will be downloading the files to a directory, so make sure it's there
// This step is not required if you have manually created the directory
let fileInfo = await tempDir.open({prefix: 'appium-app', suffix: suffix});
_fs.close(fileInfo.fd);
await fs.writeFile(fileInfo.path, await request(fileUrl));
logger.debug(`${fileUrl} downloaded to ${fileInfo.path}`);
// we use the non-promise version of request because the 'pipe' function
// won't overuse memory. request-promise has to store the whole response
// in memory (and also has encoding trickiness)
let writeStream = _fs.createWriteStream(fileInfo.path);
writeStream.on('error', (e) => logger.errorAndThrow(e));
let onClose = B.promisify(writeStream.on, writeStream)('close');
requestWithoutPromises.get(fileUrl).pipe(writeStream);
await onClose;
logger.debug(`${fileUrl} downloaded to ${fileInfo.path}`);
return fileInfo.path;
}
+2 -1
View File
@@ -31,7 +31,7 @@
"bluebird": "^2.9.25",
"lodash": "^3.9.1",
"mobile-json-wire-protocol": "latest",
"request-promise": "^0.4.2",
"request": "^2.61.0",
"source-map-support": "^0.3.2",
"teen_process": "^1.2.2",
"uuid-js": "^0.7.5",
@@ -49,6 +49,7 @@
"chai-as-promised": "^5.0.0",
"gulp": "^3.8.11",
"mochawait": "^2.0.0",
"request-promise": "^0.4.2",
"sinon": "^1.14.1",
"yargs": "^3.9.0"
}