♻ Some refactoring to prepare for patch processing

This commit is contained in:
C-3PO 2018-07-05 20:50:23 +02:00
parent 60fe546d31
commit f849744ac8
Signed by: c3po
GPG key ID: 62993C4BB4D86F24
8 changed files with 57 additions and 35 deletions

View file

@ -3,7 +3,7 @@ import * as http from 'http';
import saveResponse from './funcs/saveResponse';
/** Downloads the given URL and saves it to disk. Throws error if download fails. */
export default function downloadUrlContents({ host, path }: {host: string, path: string}): Promise<fs.ReadStream> {
export default function downloadUrlContents({ host, path }: {host: string, path: string}): Promise<string> {
return new Promise((resolve, reject) => {
//Create HTTP request
const request = http.request({

View file

@ -2,7 +2,7 @@ import * as fs from 'fs';
import * as http from 'http';
export default function saveResponse(
resolve: (fileName: fs.ReadStream) => void,
resolve: (fileName: string) => void,
reject: (reason: string) => void,
response: http.IncomingMessage,
) {
@ -57,7 +57,8 @@ export default function saveResponse(
//Return file reader
//TODO: need to automatically delete file once it is no longer used
//TODO: need to provide methods to seek through file
const stream = fs.createReadStream(tempFileName, { encoding: 'binary' }); //TODO: we may need to remove encoding since mentioning encoding automatically switches to string format
return resolve(stream);
return resolve(tempFileName);
//const stream = fs.createReadStream(tempFileName, { encoding: 'binary' }); //TODO: we may need to remove encoding since mentioning encoding automatically switches to string format
//return resolve(stream);
});
}