-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
perf(core): Skip binary files during GitHub archive tar extraction #1392
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
yamadashy
merged 1 commit into
main
from
perf/skip-binary-files-during-archive-extraction
Apr 4, 2026
+111
−1
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| import isBinaryPath from 'is-binary-path'; | ||
| import { logger } from '../../shared/logger.js'; | ||
|
|
||
| /** | ||
| * Creates a filter function for tar extraction that skips binary files. | ||
| * The filter is called with the raw tar entry path (before strip is applied), | ||
| * so we manually remove the leading segment (e.g. "repo-branch/") before checking. | ||
| */ | ||
| export const createArchiveEntryFilter = (deps = { isBinaryPath }) => { | ||
| return (entryPath: string): boolean => { | ||
| // Remove the leading directory segment that tar's strip:1 would remove | ||
| const strippedPath = entryPath.replace(/^[^/]+\//, ''); | ||
|
|
||
| if (!strippedPath) { | ||
| // Root directory entry — always allow | ||
| return true; | ||
| } | ||
|
|
||
| if (deps.isBinaryPath(strippedPath)) { | ||
| logger.trace(`Skipping binary file in archive: ${strippedPath}`); | ||
| return false; | ||
| } | ||
|
|
||
| return true; | ||
| }; | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -4,6 +4,7 @@ import * as zlib from 'node:zlib'; | |||||
| import { extract as tarExtract } from 'tar'; | ||||||
| import { RepomixError } from '../../shared/errorHandle.js'; | ||||||
| import { logger } from '../../shared/logger.js'; | ||||||
| import { createArchiveEntryFilter } from './archiveEntryFilter.js'; | ||||||
| import { | ||||||
| buildGitHubArchiveUrl, | ||||||
| buildGitHubMasterArchiveUrl, | ||||||
|
|
@@ -31,6 +32,7 @@ export interface ArchiveDownloadDeps { | |||||
| Transform: typeof Transform; | ||||||
| tarExtract: typeof tarExtract; | ||||||
| createGunzip: typeof zlib.createGunzip; | ||||||
| createArchiveEntryFilter: typeof createArchiveEntryFilter; | ||||||
| } | ||||||
|
|
||||||
| const defaultDeps: ArchiveDownloadDeps = { | ||||||
|
|
@@ -39,6 +41,7 @@ const defaultDeps: ArchiveDownloadDeps = { | |||||
| Transform, | ||||||
| tarExtract, | ||||||
| createGunzip: zlib.createGunzip, | ||||||
| createArchiveEntryFilter, | ||||||
| }; | ||||||
|
|
||||||
| /** | ||||||
|
|
@@ -164,9 +167,12 @@ const downloadAndExtractArchive = async ( | |||||
|
|
||||||
| // Stream: HTTP response -> progress tracking -> gunzip -> tar extract to disk | ||||||
| // strip: 1 removes the top-level "repo-branch/" directory from archive paths | ||||||
| // filter: skips binary files (e.g. images, fonts, executables) to avoid unnecessary disk I/O | ||||||
| const entryFilter = deps.createArchiveEntryFilter(); | ||||||
| const extractStream = deps.tarExtract({ | ||||||
| cwd: targetDirectory, | ||||||
| strip: 1, | ||||||
| filter: (entryPath: string) => entryFilter(entryPath), | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The filter callback can be simplified by passing the
Suggested change
|
||||||
| }); | ||||||
| const gunzipStream = deps.createGunzip(); | ||||||
|
|
||||||
|
|
||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| import { describe, expect, test, vi } from 'vitest'; | ||
| import { createArchiveEntryFilter } from '../../../src/core/git/archiveEntryFilter.js'; | ||
|
|
||
| vi.mock('../../../src/shared/logger'); | ||
|
|
||
| describe('archiveEntryFilter', () => { | ||
| describe('createArchiveEntryFilter', () => { | ||
| test('should allow text files', () => { | ||
| const filter = createArchiveEntryFilter(); | ||
| expect(filter('repo-main/src/index.ts')).toBe(true); | ||
| expect(filter('repo-main/README.md')).toBe(true); | ||
| expect(filter('repo-main/package.json')).toBe(true); | ||
| }); | ||
|
|
||
| test('should skip binary image files', () => { | ||
| const filter = createArchiveEntryFilter(); | ||
| expect(filter('repo-main/assets/logo.png')).toBe(false); | ||
| expect(filter('repo-main/images/photo.jpg')).toBe(false); | ||
| expect(filter('repo-main/icon.gif')).toBe(false); | ||
| }); | ||
|
|
||
| test('should skip font files', () => { | ||
| const filter = createArchiveEntryFilter(); | ||
| expect(filter('repo-main/fonts/inter.woff2')).toBe(false); | ||
| expect(filter('repo-main/fonts/roboto.woff')).toBe(false); | ||
| expect(filter('repo-main/fonts/arial.ttf')).toBe(false); | ||
| }); | ||
|
|
||
| test('should skip archive and executable files', () => { | ||
| const filter = createArchiveEntryFilter(); | ||
| expect(filter('repo-main/dist/app.exe')).toBe(false); | ||
| expect(filter('repo-main/vendor/lib.zip')).toBe(false); | ||
| }); | ||
|
|
||
| test('should allow root directory entry', () => { | ||
| const filter = createArchiveEntryFilter(); | ||
| expect(filter('repo-main/')).toBe(true); | ||
| }); | ||
|
|
||
| test('should handle nested directory paths', () => { | ||
| const filter = createArchiveEntryFilter(); | ||
| expect(filter('repo-main/src/components/Button.tsx')).toBe(true); | ||
| expect(filter('repo-main/src/assets/icons/arrow.png')).toBe(false); | ||
| }); | ||
|
|
||
| test('should strip leading segment correctly for various repo name formats', () => { | ||
| const filter = createArchiveEntryFilter(); | ||
| // Different repository name formats in tar archives | ||
| expect(filter('yamadashy-repomix-abc123/src/index.ts')).toBe(true); | ||
| expect(filter('yamadashy-repomix-abc123/logo.png')).toBe(false); | ||
| }); | ||
|
|
||
| test('should use injected isBinaryPath dependency', () => { | ||
| const mockIsBinaryPath = vi.fn().mockReturnValue(true); | ||
| const filter = createArchiveEntryFilter({ isBinaryPath: mockIsBinaryPath }); | ||
|
|
||
| const result = filter('repo-main/src/index.ts'); | ||
|
|
||
| expect(result).toBe(false); | ||
| expect(mockIsBinaryPath).toHaveBeenCalledWith('src/index.ts'); | ||
| }); | ||
|
|
||
| test('should pass stripped path to isBinaryPath', () => { | ||
| const mockIsBinaryPath = vi.fn().mockReturnValue(false); | ||
| const filter = createArchiveEntryFilter({ isBinaryPath: mockIsBinaryPath }); | ||
|
|
||
| filter('repo-main/src/deep/file.ts'); | ||
|
|
||
| expect(mockIsBinaryPath).toHaveBeenCalledWith('src/deep/file.ts'); | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The filter should explicitly check the entry type to ensure it only applies to regular files. This prevents potential issues where directories or other entry types with names resembling binary extensions (e.g., a repository named
test.zip) might be incorrectly skipped if the stripping logic fails or the trailing slash is missing. Using theentryobject provided bytaris a more robust approach.