Skip to content

feat: implement binary format encoding/decoding for multi-file support #45

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
merged 1 commit into from
Jun 6, 2025

Conversation

nullcoder
Copy link
Owner

Summary

Implements efficient binary format encoding/decoding for multi-file support, completing issue #37.

Changes

New Files

  • lib/binary.ts: Complete binary format implementation with:

    • encodeFiles() - Encodes multiple files into compact binary format
    • decodeFiles() - Decodes binary data back to files with validation
    • validateBinaryFormat() - Quick format validation without full decode
    • extractHeader() - Reads header information
    • Helper functions for byte conversions
  • lib/binary.test.ts: Comprehensive test suite with 35 tests

Binary Format Structure

[4 bytes: Magic "GPST" (0x47505354)]
[1 byte: Version (1)]
[2 bytes: File count]
[4 bytes: Total size]
For each file:
  [2 bytes: Filename length]
  [N bytes: Filename (UTF-8)]
  [4 bytes: Content length]
  [N bytes: Content (UTF-8)]
  [1 byte: Language length]
  [N bytes: Language (UTF-8, optional)]

Error Handling Improvements

  • Removed duplicate BinaryFormatError (kept InvalidBinaryFormatError)
  • Removed generic ValidationError in favor of specific errors:
    • BadRequestError for general validation failures
    • FileTooLargeError for individual file size violations
    • TooManyFilesError for file count violations
    • PayloadTooLargeError for total size violations

Size Limits Enforced

  • Max file size: 500KB per file
  • Max total size: 5MB
  • Max file count: 20 files
  • Max filename length: 255 characters
  • Max language identifier: 50 characters

Test Coverage

All 35 tests passing, covering:

  • ✅ Normal operations (single/multiple files)
  • ✅ Edge cases (empty files, Unicode, special characters)
  • ✅ Error conditions and validation
  • ✅ Size limit enforcement
  • ✅ Format corruption detection
  • ✅ Round-trip data integrity

Test Plan

  • Unit tests pass
  • Handles Unicode filenames and content correctly
  • Enforces all size limits
  • Detects and rejects corrupted data
  • Efficient packing (minimal overhead)

Closes #37

🤖 Generated with Claude Code

#37)

- Create lib/binary.ts with complete binary format implementation
- Add encodeFiles() function with magic number "GPST" and version support
- Add decodeFiles() function with comprehensive validation
- Add validateBinaryFormat() for quick format validation
- Add extractHeader() to read header without full decode
- Implement efficient binary packing with proper size limit enforcement
- Use specific error types instead of generic ValidationError
- Add comprehensive test suite with 35 tests covering:
  - Normal operations (single/multiple files)
  - Edge cases (empty files, Unicode, special characters)
  - Error conditions and size limits
  - Format validation and corruption detection

Binary format structure:
- 4 bytes: Magic number "GPST" (0x47505354)
- 1 byte: Version
- 2 bytes: File count
- 4 bytes: Total size
- Per file: filename length + name + content length + content + language

This implementation provides efficient multi-file packing while maintaining
data integrity and enforcing security limits.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
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
ghostpaste 2d0a80a Visit preview Jun 06 2025, 08:33 AM

@nullcoder nullcoder merged commit c3e86c5 into main Jun 6, 2025
1 check passed
@nullcoder nullcoder deleted the feat/binary-format branch June 6, 2025 09:19
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.

feat: implement binary format encoding/decoding for multi-file support
1 participant