Table of Contents

Class ArchiveFormatDetector

Namespace
Archiver.Core.Services
Assembly
Archiver.Core.dll

Detects archive format from magic bytes only — no extension reliance, matching this codebase's existing ZIP signature-sniffing convention (see ZipArchiveService.IsZipFile). Used by ExtractionRouter to decide which service (IArchiveService vs ITarService) should handle a given archive path.

public static class ArchiveFormatDetector
Inheritance
ArchiveFormatDetector
Inherited Members

Methods

Detect(string)

Detects an archive's real format from its magic bytes. Returns Unknown on any read failure.

public static ArchiveFormat Detect(string path)

Parameters

path string

Returns

ArchiveFormat

FormatFromExtension(string)

The format an archive's extension names, or Unknown — no disk I/O (T-F212). Not the security boundary: Detect(string) still decides at run time.

public static ArchiveFormat FormatFromExtension(string fileName)

Parameters

fileName string

Returns

ArchiveFormat

IsEncryptedRar(string)

Detects RAR5 encryption directly from the archive's own block structure — no tar.exe invocation needed. RAR headers are never compressed (only file data is), so walking the block/extra-area chain is real, bounded metadata parsing, not decryption. Two cases: (1) the very first block has type 4 ("Archive encryption header") — see IsRarHeaderEncrypted(string); (2) the first File Header block (following the normal Main Archive Header) carries an "Encryption" extra-area record (type 1) — only that entry's data is password-protected, same first-entry-only fidelity ZipArchiveService.IsEncryptedZip already accepts for ZIP. Use this (not the narrower IsRarHeaderEncrypted(string)) wherever extraction is about to be attempted — both cases fail extraction, only the header-encrypted case fails listing. Byte offsets and the RAR5 vint/block layout were confirmed empirically against real WinRAR-created fixtures (encrypted.rar, encrypted_headers.rar) — see DECISIONS.md's T-F113 entry. Returns false (not an error) for any parse failure or non-RAR5 input — this is a fast-path UX improvement, not the actual security boundary (ScanForUnsafeEntriesAsync's whole-archive pre-scan still runs regardless).

public static bool IsEncryptedRar(string path)

Parameters

path string

Returns

bool

IsRarHeaderEncrypted(string)

Detects RAR5 "archive encryption header" (block type 4) as the very first block — the whole archive, including every filename, is unreadable without a password (tar -tf itself fails). Narrower than IsEncryptedRar(string): does NOT flag the common data-only-encryption case, where filenames are still readable and listing should still succeed (matching ZipArchiveService.ListEntriesAsync's parity for an encrypted ZIP — only extraction refuses, not browsing). Byte offsets confirmed empirically against real WinRAR-created fixtures — see DECISIONS.md's T-F113 entry. Returns false for any parse failure or non-RAR5 input.

public static bool IsRarHeaderEncrypted(string path)

Parameters

path string

Returns

bool

IsRecognizedArchiveExtension(string)

Fast, no-disk-I/O extension check — used only where Detect(string)'s magic-byte sniff can't run yet (e.g. an in-archive entry not extracted). Not the security boundary.

public static bool IsRecognizedArchiveExtension(string fileName)

Parameters

fileName string

Returns

bool