diff --git a/modules/__mocks__/npmMock.js b/modules/__mocks__/npmMock.js index ba5e55f..4014ac5 100644 --- a/modules/__mocks__/npmMock.js +++ b/modules/__mocks__/npmMock.js @@ -1,5 +1,6 @@ import fs from 'fs'; import path from 'path'; +import gunzip from 'gunzip-maybe'; function getPackageInfo(packageName) { const file = path.resolve(__dirname, `./metadata/${packageName}.json`); @@ -29,5 +30,5 @@ export function getPackage(packageName, version) { `./packages/${packageName}-${version}.tgz` ); - return fs.existsSync(file) ? fs.createReadStream(file) : null; + return fs.existsSync(file) ? fs.createReadStream(file).pipe(gunzip()) : null; } diff --git a/modules/actions/serveDirectoryBrowser.js b/modules/actions/serveDirectoryBrowser.js index b6a85f5..8ab3f09 100644 --- a/modules/actions/serveDirectoryBrowser.js +++ b/modules/actions/serveDirectoryBrowser.js @@ -1,5 +1,4 @@ import path from 'path'; -import gunzip from 'gunzip-maybe'; import tar from 'tar-stream'; import asyncHandler from '../utils/asyncHandler.js'; @@ -15,7 +14,6 @@ async function findMatchingEntries(stream, filename) { const entries = {}; stream - .pipe(gunzip()) .pipe(tar.extract()) .on('error', reject) .on('entry', async (header, stream, next) => { diff --git a/modules/actions/serveDirectoryMetadata.js b/modules/actions/serveDirectoryMetadata.js index 1e92853..c38d848 100644 --- a/modules/actions/serveDirectoryMetadata.js +++ b/modules/actions/serveDirectoryMetadata.js @@ -1,5 +1,4 @@ import path from 'path'; -import gunzip from 'gunzip-maybe'; import tar from 'tar-stream'; import asyncHandler from '../utils/asyncHandler.js'; @@ -16,7 +15,6 @@ async function findMatchingEntries(stream, filename) { entries[filename] = { path: filename, type: 'directory' }; stream - .pipe(gunzip()) .pipe(tar.extract()) .on('error', reject) .on('entry', async (header, stream, next) => { diff --git a/modules/actions/serveFileBrowser.js b/modules/actions/serveFileBrowser.js index d7916a9..cb41534 100644 --- a/modules/actions/serveFileBrowser.js +++ b/modules/actions/serveFileBrowser.js @@ -1,4 +1,3 @@ -import gunzip from 'gunzip-maybe'; import tar from 'tar-stream'; import asyncHandler from '../utils/asyncHandler.js'; @@ -18,7 +17,6 @@ async function findEntry(stream, filename) { let foundEntry = null; stream - .pipe(gunzip()) .pipe(tar.extract()) .on('error', reject) .on('entry', async (header, stream, next) => { diff --git a/modules/actions/serveFileMetadata.js b/modules/actions/serveFileMetadata.js index d72e5b3..030be30 100644 --- a/modules/actions/serveFileMetadata.js +++ b/modules/actions/serveFileMetadata.js @@ -1,4 +1,3 @@ -import gunzip from 'gunzip-maybe'; import tar from 'tar-stream'; import asyncHandler from '../utils/asyncHandler.js'; @@ -13,7 +12,6 @@ async function findEntry(stream, filename) { let foundEntry = null; stream - .pipe(gunzip()) .pipe(tar.extract()) .on('error', reject) .on('entry', async (header, stream, next) => { diff --git a/modules/middleware/findEntry.js b/modules/middleware/findEntry.js index 498e5af..0f0388d 100644 --- a/modules/middleware/findEntry.js +++ b/modules/middleware/findEntry.js @@ -1,5 +1,4 @@ import path from 'path'; -import gunzip from 'gunzip-maybe'; import tar from 'tar-stream'; import asyncHandler from '../utils/asyncHandler.js'; @@ -67,7 +66,6 @@ function searchEntries(stream, filename) { } stream - .pipe(gunzip()) .pipe(tar.extract()) .on('error', reject) .on('entry', async (header, stream, next) => { diff --git a/modules/utils/npm.js b/modules/utils/npm.js index 616ca6a..ad3dd4e 100644 --- a/modules/utils/npm.js +++ b/modules/utils/npm.js @@ -1,5 +1,6 @@ import url from 'url'; import https from 'https'; +import gunzip from 'gunzip-maybe'; import LRUCache from 'lru-cache'; import debug from './debug.js'; @@ -179,7 +180,9 @@ export async function getPackage(packageName, version) { const res = await get(options); if (res.statusCode === 200) { - return res; + const stream = res.pipe(gunzip()); + // stream.pause(); + return stream; } const data = await bufferStream(res);