Skip to content

Add two functions to retrieve more file data#230

Open
ScaledLizard wants to merge 2 commits into
twogood:mainfrom
ScaledLizard:pr-file-accessors
Open

Add two functions to retrieve more file data#230
ScaledLizard wants to merge 2 commits into
twogood:mainfrom
ScaledLizard:pr-file-accessors

Conversation

@ScaledLizard
Copy link
Copy Markdown

@ScaledLizard ScaledLizard commented Apr 8, 2026

Add two functions to retrieve more file data: unshield_file_size_compressed, unshield_file_flags_raw.

Since the functions return uint64_t and uint16_t, we should also add this:

#include <stdint.h>

Summary by CodeRabbit

  • New Features
    • Added new API functions to access compressed file sizes from archives
    • Added new API functions to access raw file flags from archives

Comment thread lib/libunshield.h
UNSHIELD_API int unshield_file_directory (Unshield* unshield, int index);
UNSHIELD_API size_t unshield_file_size (Unshield* unshield, int index);
UNSHIELD_API uint64_t unshield_file_size_compressed(Unshield* unshield, int index);
UNSHIELD_API uint16_t unshield_file_flags_raw (Unshield* unshield, int index);
Copy link
Copy Markdown
Contributor

@kratz00 kratz00 Apr 8, 2026

Choose a reason for hiding this comment

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

Would it not make sense to also expose https://github.com/twogood/unshield/blob/main/lib/cabfile.h#L60-L63
otherwise nobody knows what the magic uint16 means?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Yes, the flags also need to be moved or copied to the public header.

Comment thread lib/file.c Outdated
Comment thread lib/file.c Outdated
Let's have consistent signatures and potentially fix these in twogood#227

Co-authored-by: Steffen Pankratz <kratz00@gmx.de>
Signed-off-by: David Eriksson <david@activout.se>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 17, 2026

Walkthrough

Two new public API functions are added to expose file metadata: unshield_file_size_compressed() retrieves the compressed file size, and unshield_file_flags_raw() retrieves raw file flags. Both follow existing error-handling patterns and return default values on lookup failure.

Changes

Cohort / File(s) Summary
New Accessor Functions
lib/libunshield.h, lib/file.c
Added two new public API functions for querying file metadata: unshield_file_size_compressed() returning uint64_t and unshield_file_flags_raw() returning uint16_t. Includes header with <stdint.h> for fixed-width integer types.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~5 minutes

Poem

🐰 Two new friends hop into the fold,
Compressed sizes and flags to be told,
Simple and clean, they follow the way,
Of accessor functions here to stay! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding two new accessor functions (unshield_file_size_compressed and unshield_file_flags_raw) to retrieve additional file metadata from the public API.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@twogood
Copy link
Copy Markdown
Owner

twogood commented Apr 17, 2026

It seems I had commented the below on #227 instead of this PR, sorry about that!

Let's fix the warnings in the other PR [#227] (with or without adding UNSHIELD_API) and don't add UNSHIELD_API in this PR.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

♻️ Duplicate comments (1)
lib/libunshield.h (1)

122-122: ⚠️ Potential issue | 🟠 Major

Expose the file flag constants alongside unshield_file_flags_raw.

Without the FILE_* flag definitions (currently in internal lib/cabfile.h), consumers of unshield_file_flags_raw have no way to interpret the returned uint16_t. Please move/copy the relevant flag constants (e.g. FILE_COMPRESSED, FILE_INVALID, FILE_SPLIT, FILE_OBFUSCATED) into this public header so the new accessor is actually usable.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lib/libunshield.h` at line 122, Add the file flag constants used by
unshield_file_flags_raw to the public header so callers can interpret the
returned uint16_t: copy or move the relevant definitions (e.g. FILE_COMPRESSED,
FILE_INVALID, FILE_SPLIT, FILE_OBFUSCATED and any associated bit masks) from
internal lib/cabfile.h into lib/libunshield.h, ensure they use the same integer
types and values as the originals, and keep them guarded by the same visibility
macro (UNSHIELD_API or plain defines) so consumers can include libunshield.h and
decode the flags returned by unshield_file_flags_raw.
🧹 Nitpick comments (1)
lib/libunshield.h (1)

121-122: Optional: align declarations with the existing column layout.

Neighboring declarations (lines 115–120) align return types into a fixed column; the two new lines break that alignment and push the parameter list out. Purely cosmetic — feel free to ignore.

Proposed tweak
-UNSHIELD_API uint64_t    unshield_file_size_compressed(Unshield* unshield, int index);
-UNSHIELD_API uint16_t    unshield_file_flags_raw      (Unshield* unshield, int index);
+UNSHIELD_API uint64_t    unshield_file_size_compressed (Unshield* unshield, int index);
+UNSHIELD_API uint16_t    unshield_file_flags_raw       (Unshield* unshield, int index);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lib/libunshield.h` around lines 121 - 122, The two new declarations
unshield_file_size_compressed and unshield_file_flags_raw break the header's
column alignment; update their spacing to match the existing declaration layout
(align the return types and push parameter lists into the same column as other
prototypes) so they visually line up with the neighboring declarations like the
ones at lines 115–120; adjust spaces between UNSHIELD_API, the return type
(uint64_t / uint16_t), the function name, and the parameter list to follow the
established column alignment.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@lib/libunshield.h`:
- Line 122: Add the file flag constants used by unshield_file_flags_raw to the
public header so callers can interpret the returned uint16_t: copy or move the
relevant definitions (e.g. FILE_COMPRESSED, FILE_INVALID, FILE_SPLIT,
FILE_OBFUSCATED and any associated bit masks) from internal lib/cabfile.h into
lib/libunshield.h, ensure they use the same integer types and values as the
originals, and keep them guarded by the same visibility macro (UNSHIELD_API or
plain defines) so consumers can include libunshield.h and decode the flags
returned by unshield_file_flags_raw.

---

Nitpick comments:
In `@lib/libunshield.h`:
- Around line 121-122: The two new declarations unshield_file_size_compressed
and unshield_file_flags_raw break the header's column alignment; update their
spacing to match the existing declaration layout (align the return types and
push parameter lists into the same column as other prototypes) so they visually
line up with the neighboring declarations like the ones at lines 115–120; adjust
spaces between UNSHIELD_API, the return type (uint64_t / uint16_t), the function
name, and the parameter list to follow the established column alignment.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: bedb9870-a1a1-4c0b-a022-510ba54c6d86

📥 Commits

Reviewing files that changed from the base of the PR and between cbed3d1 and de20f1c.

📒 Files selected for processing (2)
  • lib/file.c
  • lib/libunshield.h

@twogood twogood self-assigned this Apr 17, 2026
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