Skip to content

Conversation

@jmgilman
Copy link
Contributor

Summary

  • Add DirStats method to Blob that returns file count, total bytes, and compressed bytes for files under a directory prefix
  • Add DirStats struct type to hold the statistics
  • Re-export DirStats type from top-level blob package

Motivation

Getting statistics about files under a prefix previously required manual iteration with complex prefix-matching logic. This method eliminates that boilerplate.

Changes

The DirStats method:

  • Normalizes the prefix before use (/etc/nginx/ and etc/nginx are equivalent)
  • Handles exact file matches (DirStats("etc/hosts") returns stats for that single file)
  • Returns zero values for non-existent or invalid prefixes (including path traversal attempts)

Test plan

  • Table-driven tests for various prefixes (root, subdirectory, nested)
  • Tests for path normalization (leading/trailing slashes)
  • Tests for exact file match behavior
  • Tests for invalid paths (../escape, /../etc)
  • Tests for compressed archives (verifies CompressedBytes < TotalBytes)
  • All CI checks pass

🤖 Generated with Claude Code

Add a DirStats method to Blob that returns file count, total bytes, and
compressed bytes for files under a directory prefix. This eliminates the
need for manual iteration with complex prefix-matching logic.

The method:
- Normalizes the prefix before use ("/etc/nginx/" and "etc/nginx" are equivalent)
- Handles exact file matches (DirStats("etc/hosts") returns stats for that file)
- Returns zero values for non-existent or invalid prefixes
- Re-exports the DirStats type from the top-level blob package

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@cloudflare-workers-and-pages
Copy link

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
blob 7fcddbc Commit Preview URL

Branch Preview URL
Jan 23 2026, 05:11 AM

@jmgilman jmgilman merged commit e9ed59a into master Jan 23, 2026
10 checks passed
@jmgilman jmgilman deleted the feat/dir-stats branch January 23, 2026 05:25
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