Skip to content

Conversation

@manascb1344
Copy link

This PR adds a new --max-bytes NUM flag that tells ripgrep to only read and search the first NUM bytes of each file or stream. This is useful when matches are expected only in a small header region (for example HTTP headers in large cache files), and can greatly reduce I/O.

  • New flag: --max-bytes NUM (per file/stream)
  • Applied consistently to mmap, regular files, stdin, and multiline searches
  • Multiline preallocation is capped by min(NUM, file_size) when --max-bytes is set
  • Plays well with --max-count 1 for fast “find first hit in header” use cases
  • Includes tests for normal files, stdin, and binary-looking files

Implements the feature requested in #3035.

@manascb1344
Copy link
Author

@BurntSushi
All tests and CI checks are now passing for this PR. When you have a moment, could you please review and consider merging the --max-bytes flag change?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant