♻ Some refactoring to prepare for patch processing
This commit is contained in:
parent
60fe546d31
commit
f849744ac8
8 changed files with 57 additions and 35 deletions
|
@ -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({
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue