(
baseURL, destDir, filename)
| 46 | |
| 47 | // Downloads a test file only once and returns the buffer for the file. |
| 48 | export async function fetchOnceAndSaveToDiskWithBuffer( |
| 49 | baseURL, destDir, filename) { |
| 50 | |
| 51 | return new Promise(async (resolve, reject) => { |
| 52 | const url = `${baseURL}${filename}.gz`; |
| 53 | const localPath = path.join(destDir, filename); |
| 54 | if (await exists(localPath)) { |
| 55 | resolve(readFile(localPath)); |
| 56 | return; |
| 57 | } |
| 58 | const file = fs.createWriteStream(filename); |
| 59 | console.log(` * Downloading from: ${url}`); |
| 60 | let httpModule; |
| 61 | if (url.indexOf('https://') === 0) { |
| 62 | httpModule = https; |
| 63 | } else if (url.indexOf('http://') === 0) { |
| 64 | httpModule = http; |
| 65 | } else { |
| 66 | return reject(`Unrecognized protocol in URL: ${url}`); |
| 67 | } |
| 68 | |
| 69 | httpModule.get(url, (response) => { |
| 70 | const unzip = zlib.createGunzip(); |
| 71 | response.pipe(unzip).pipe(file); |
| 72 | unzip.on('end', async () => { |
| 73 | await rename(filename, localPath); |
| 74 | resolve(readFile(localPath)); |
| 75 | }); |
| 76 | }); |
| 77 | }); |
| 78 | } |
| 79 | |
| 80 | function loadHeaderValues(buffer, headerLength) { |
| 81 | const headerValues = []; |
no outgoing calls
no test coverage detected