/
githubmirror
/
angular-cli
Обзор
Документация
Войти
/
githubmirror
/
angular-cli
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
tests/e2e/utils/tar.ts
48 строк
1 KB
Alan Agius
test: migrate legacy CLI tests to e2e directory
17 дек 2025, 19:36
17 дек 2025, 19:36
7d3e0ad
Код
Авторство
О чём код?
/** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.dev/license */ import { createReadStream } from 'node:fs'; import { normalize } from 'node:path'; import { createGunzip } from 'node:zlib'; import { extract } from 'tar-stream'; /** * Extract and return the contents of a single file out of a tar file. * * @param tarball the tar file to extract from * @param filePath the path of the file to extract * @returns the Buffer of file or an error on fs/tar error or file not found */ export function extractFile(tarball: string, filePath: string): Promise<Buffer> { const normalizedFilePath = normalize(filePath); return new Promise((resolve, reject) => { const extractor = extract(); extractor.on('entry', (header, stream, next) => { if (normalize(header.name) !== normalizedFilePath) { stream.resume(); next(); return; } const chunks: Buffer[] = []; stream.on('data', (chunk) => chunks.push(chunk)); stream.on('error', reject); stream.on('end', () => { resolve(Buffer.concat(chunks)); next(); }); }); extractor.on('finish', () => reject(new Error(`'${filePath}' not found in '${tarball}'.`))); createReadStream(tarball).pipe(createGunzip()).pipe(extractor).on('error', reject); }); }