Skip to content

Add Entry.LengthBytes#163

Merged
jas88 merged 5 commits intojas88:mainfrom
YoshiRulz:length
Dec 6, 2025
Merged

Add Entry.LengthBytes#163
jas88 merged 5 commits intojas88:mainfrom
YoshiRulz:length

Conversation

@YoshiRulz
Copy link
Contributor

@YoshiRulz YoshiRulz commented Nov 13, 2025

...using archive_entry_size. The docs mention a archive_entry_size_is_set but I guess it's only unset if you're creating an archive, since the unit test checks that a directory has length 0 and that passed it's documented as returning 0 when archive_entry_size_is_set is false.

High-level PR Summary

This PR adds a LengthBytes property to the Entry class that exposes the size of archive entries using the underlying archive_entry_size function. The new property is populated during entry creation and is used to set the Length property of the FileStream class, replacing a NotSupportedException with an actual value. Tests are updated to verify that the length is correctly extracted for files and directories (including 0-byte files, directories, and larger files like the 1GB zero file).

⏱️ Estimated Review Time: 15-30 minutes

💡 Review Order Suggestion
Order File Path
1 Test.LibArchive.Net/Test.LibArchive.Net.csproj
2 LibArchive.Net/LibArchiveReader.cs
3 Test.LibArchive.Net/ReaderTests.cs
⚠️ Inconsistent Changes Detected
File Path Warning
Test.LibArchive.Net/Test.LibArchive.Net.csproj The project file changes simplify LangVersion and ImplicitUsings configuration by removing conditional logic for net462. This appears to be a build configuration cleanup unrelated to adding the LengthBytes property.
Test.LibArchive.Net/ReaderTests.cs The PR removes conditional compilation for NET462 compatibility (removing the class-based ExtractedEntry implementation) and adds an IsExternalInit polyfill for records. These changes are C# language feature modernization unrelated to the LengthBytes feature.

Need help? Join our Discord

Copy link

@recurseml recurseml bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review by RecurseML

🔍 Review performed on c697ed4..43f6882

  Severity     Location     Issue     Delete  
High LibArchive.Net/LibArchiveReader.cs:384 Integer truncation for large files
High LibArchive.Net/LibArchiveReader.cs:426 Integer truncation for large files
✅ Files analyzed, no issues (2)

Test.LibArchive.Net/ReaderTests.cs
Test.LibArchive.Net/Test.LibArchive.Net.csproj

@jas88
Copy link
Owner

jas88 commented Nov 27, 2025

@YoshiRulz Could we handle it better when archive_entry_size returns 0 for unknown length files?

@YoshiRulz
Copy link
Contributor Author

I don't know how much better that could be. Maybe -1 for dirs and 0 for empty files? You're already exposing the type.

@jas88
Copy link
Owner

jas88 commented Nov 27, 2025

@YoshiRulz I mean to distinguish between "0 byte file" and "file of unknown length" - probably use long? instead of plain long. I'll take a closer look at it in a bit.

- Use archive_entry_size_is_set() to check if size is known
- LengthBytes is now long? (null when size unknown, value when set)
- FileStream.Length throws NotSupportedException when size unknown
- Fix IsExternalInit preprocessor symbol (NET5_0_OR_GREATER)
Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 3 files

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a LengthBytes property to the Entry class that exposes archive entry sizes via the libarchive archive_entry_size function. The property returns a nullable long (null when size is unknown) and is used to populate the FileStream.Length property, replacing a NotSupportedException with actual size data when available.

Key changes:

  • Added archive_entry_size and archive_entry_size_is_set P/Invoke declarations for both NET7+ (LibraryImport) and older frameworks (DllImport)
  • Implemented Entry.LengthBytes property that checks if size is set before retrieving it
  • Updated FileStream to accept and expose the length value
  • Enhanced tests to verify length extraction for various file types (directories, empty files, large files)

However, the PR introduces critical compatibility issues with the net462 target framework by removing language version constraints and using C# 9+ features (records) without conditional compilation.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 21 comments.

File Description
Test.LibArchive.Net/Test.LibArchive.Net.csproj Removes conditional LangVersion/ImplicitUsings for net462, breaking compatibility with this still-targeted framework
Test.LibArchive.Net/ReaderTests.cs Adds LengthBytes to test assertions; converts ExtractedEntry to unconditional record syntax incompatible with net462; adds IsExternalInit polyfill
LibArchive.Net/LibArchiveReader.cs Implements LengthBytes property using archive_entry_size API; updates FileStream to use length; includes whitespace formatting changes

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@jas88 jas88 merged commit 31aade3 into jas88:main Dec 6, 2025
5 checks passed
@YoshiRulz YoshiRulz deleted the length branch December 6, 2025 14:15
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.

3 participants