Skip to content

Conversation

@jmgilman
Copy link
Contributor

Summary

  • Implement blob cat command for printing file contents to stdout
  • Implement blob cp command for copying files/directories from archives to local filesystem
  • Both commands use HTTP range requests for efficient partial downloads

Features

blob cat <ref> <file>...

  • Print file contents to stdout (binary-safe)
  • Multiple files concatenated in order
  • Validates files exist and rejects directories before output
  • Normalizes leading slashes for consistent path handling

blob cp <ref>:<path>... <dest>

  • Copy files/directories from archive to local filesystem
  • Detects source type (file vs directory) from archive using Stat()
  • Supports multiple sources from different refs
  • Flags:
    • --recursive/-r (default: true) - copy directories recursively
    • --preserve - preserve file permissions and timestamps
    • --force/-f - overwrite existing files

Implementation Details

  • Lazy archive loading: only manifest + index downloaded upfront
  • File data fetched via HTTP range requests on demand
  • Source type detection uses archive.Stat() (not just trailing slash)
  • Consistent overwrite behavior: skip existing by default
  • Check destination exists before reading file content (avoids unnecessary downloads)

Test plan

  • Unit tests for argument parsing
  • Unit tests for destination validation
  • Unit tests for copy mode detection
  • Linting passes
  • All tests pass

🤖 Generated with Claude Code

Add two new commands for efficient file access from blob archives:

cat command:
- Print file contents to stdout using HTTP range requests
- Support multiple files (concatenated in order)
- Validate files exist and reject directories before output
- Normalize leading slashes for consistent path handling
- Respect --quiet flag after validation

cp command:
- Copy files/directories from archive to local filesystem
- Parse ref:/path format (e.g., ghcr.io/repo:v1:/config.json)
- Detect source type (file vs directory) from archive using Stat()
- Support multiple sources from different refs (grouped to avoid re-pulling)
- Flags: --recursive/-r (default: true), --preserve, --force/-f
- Consistent overwrite behavior: skip existing by default, use -f to overwrite
- Check destination exists before reading file content (avoid unnecessary downloads)

Both commands use lazy archive loading - only manifest + index are downloaded
upfront, with actual file data fetched via HTTP range requests on demand.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@jmgilman jmgilman merged commit 3e60c94 into master Jan 23, 2026
5 checks passed
@jmgilman jmgilman deleted the feat/cat-cp-commands branch January 23, 2026 01:41
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.

2 participants