Consolidate gunzip logic
This commit is contained in:
parent
746a6fddf5
commit
be843179d4
|
@ -1,5 +1,6 @@
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
import gunzip from 'gunzip-maybe';
|
||||||
|
|
||||||
function getPackageInfo(packageName) {
|
function getPackageInfo(packageName) {
|
||||||
const file = path.resolve(__dirname, `./metadata/${packageName}.json`);
|
const file = path.resolve(__dirname, `./metadata/${packageName}.json`);
|
||||||
|
@ -29,5 +30,5 @@ export function getPackage(packageName, version) {
|
||||||
`./packages/${packageName}-${version}.tgz`
|
`./packages/${packageName}-${version}.tgz`
|
||||||
);
|
);
|
||||||
|
|
||||||
return fs.existsSync(file) ? fs.createReadStream(file) : null;
|
return fs.existsSync(file) ? fs.createReadStream(file).pipe(gunzip()) : null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import gunzip from 'gunzip-maybe';
|
|
||||||
import tar from 'tar-stream';
|
import tar from 'tar-stream';
|
||||||
|
|
||||||
import asyncHandler from '../utils/asyncHandler.js';
|
import asyncHandler from '../utils/asyncHandler.js';
|
||||||
|
@ -15,7 +14,6 @@ async function findMatchingEntries(stream, filename) {
|
||||||
const entries = {};
|
const entries = {};
|
||||||
|
|
||||||
stream
|
stream
|
||||||
.pipe(gunzip())
|
|
||||||
.pipe(tar.extract())
|
.pipe(tar.extract())
|
||||||
.on('error', reject)
|
.on('error', reject)
|
||||||
.on('entry', async (header, stream, next) => {
|
.on('entry', async (header, stream, next) => {
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import gunzip from 'gunzip-maybe';
|
|
||||||
import tar from 'tar-stream';
|
import tar from 'tar-stream';
|
||||||
|
|
||||||
import asyncHandler from '../utils/asyncHandler.js';
|
import asyncHandler from '../utils/asyncHandler.js';
|
||||||
|
@ -16,7 +15,6 @@ async function findMatchingEntries(stream, filename) {
|
||||||
entries[filename] = { path: filename, type: 'directory' };
|
entries[filename] = { path: filename, type: 'directory' };
|
||||||
|
|
||||||
stream
|
stream
|
||||||
.pipe(gunzip())
|
|
||||||
.pipe(tar.extract())
|
.pipe(tar.extract())
|
||||||
.on('error', reject)
|
.on('error', reject)
|
||||||
.on('entry', async (header, stream, next) => {
|
.on('entry', async (header, stream, next) => {
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
import gunzip from 'gunzip-maybe';
|
|
||||||
import tar from 'tar-stream';
|
import tar from 'tar-stream';
|
||||||
|
|
||||||
import asyncHandler from '../utils/asyncHandler.js';
|
import asyncHandler from '../utils/asyncHandler.js';
|
||||||
|
@ -18,7 +17,6 @@ async function findEntry(stream, filename) {
|
||||||
let foundEntry = null;
|
let foundEntry = null;
|
||||||
|
|
||||||
stream
|
stream
|
||||||
.pipe(gunzip())
|
|
||||||
.pipe(tar.extract())
|
.pipe(tar.extract())
|
||||||
.on('error', reject)
|
.on('error', reject)
|
||||||
.on('entry', async (header, stream, next) => {
|
.on('entry', async (header, stream, next) => {
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
import gunzip from 'gunzip-maybe';
|
|
||||||
import tar from 'tar-stream';
|
import tar from 'tar-stream';
|
||||||
|
|
||||||
import asyncHandler from '../utils/asyncHandler.js';
|
import asyncHandler from '../utils/asyncHandler.js';
|
||||||
|
@ -13,7 +12,6 @@ async function findEntry(stream, filename) {
|
||||||
let foundEntry = null;
|
let foundEntry = null;
|
||||||
|
|
||||||
stream
|
stream
|
||||||
.pipe(gunzip())
|
|
||||||
.pipe(tar.extract())
|
.pipe(tar.extract())
|
||||||
.on('error', reject)
|
.on('error', reject)
|
||||||
.on('entry', async (header, stream, next) => {
|
.on('entry', async (header, stream, next) => {
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import gunzip from 'gunzip-maybe';
|
|
||||||
import tar from 'tar-stream';
|
import tar from 'tar-stream';
|
||||||
|
|
||||||
import asyncHandler from '../utils/asyncHandler.js';
|
import asyncHandler from '../utils/asyncHandler.js';
|
||||||
|
@ -67,7 +66,6 @@ function searchEntries(stream, filename) {
|
||||||
}
|
}
|
||||||
|
|
||||||
stream
|
stream
|
||||||
.pipe(gunzip())
|
|
||||||
.pipe(tar.extract())
|
.pipe(tar.extract())
|
||||||
.on('error', reject)
|
.on('error', reject)
|
||||||
.on('entry', async (header, stream, next) => {
|
.on('entry', async (header, stream, next) => {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import url from 'url';
|
import url from 'url';
|
||||||
import https from 'https';
|
import https from 'https';
|
||||||
|
import gunzip from 'gunzip-maybe';
|
||||||
import LRUCache from 'lru-cache';
|
import LRUCache from 'lru-cache';
|
||||||
|
|
||||||
import debug from './debug.js';
|
import debug from './debug.js';
|
||||||
|
@ -179,7 +180,9 @@ export async function getPackage(packageName, version) {
|
||||||
const res = await get(options);
|
const res = await get(options);
|
||||||
|
|
||||||
if (res.statusCode === 200) {
|
if (res.statusCode === 200) {
|
||||||
return res;
|
const stream = res.pipe(gunzip());
|
||||||
|
// stream.pause();
|
||||||
|
return stream;
|
||||||
}
|
}
|
||||||
|
|
||||||
const data = await bufferStream(res);
|
const data = await bufferStream(res);
|
||||||
|
|
Loading…
Reference in New Issue