Table of Contents

Class ZipEntryDetector

Namespace
HeroKit.FileTypes
Assembly
HeroKit.FileTypes.dll

Detects a ZIP-based file type, such as DOCX, ODT, EPUB, JAR or APK, by the names of the entries in the header.

public sealed class ZipEntryDetector : IFileTypeDetector
Inheritance
ZipEntryDetector
Implements
Inherited Members
Extension Methods

Examples

new ZipEntryDetector("word/");                                       // DOCX
ZipEntryDetector.ForMimeTypeEntry("application/vnd.oasis.opendocument.text"); // ODT

Remarks

The detector reads entry names without decompressing anything: the local file headers from the start of the file and, when FileTypeRegistry reads a seekable stream, the central directory at the end of the file. From a span with only the first bytes, later entries are not seen, so give ZIP-based types the ZIP type as Parent.

Constructors

ZipEntryDetector(string)

Creates a detector that matches a ZIP file with an entry whose name starts with entryNamePrefix.

public ZipEntryDetector(string entryNamePrefix)

Parameters

entryNamePrefix string

The start of the entry name, for example "word/" or "AndroidManifest.xml". Case-sensitive.

Exceptions

ArgumentException

entryNamePrefix is empty.

Methods

ForMimeTypeEntry(string)

Creates a detector for OpenDocument and EPUB style files: an uncompressed "mimetype" entry that holds mimeType.

public static ZipEntryDetector ForMimeTypeEntry(string mimeType)

Parameters

mimeType string

The content of the "mimetype" entry, for example "application/epub+zip".

Returns

ZipEntryDetector

The detector.

Exceptions

ArgumentException

mimeType is empty.

IsMatch(ReadOnlySpan<byte>)

Checks whether the first bytes of a file belong to the file type.

public bool IsMatch(ReadOnlySpan<byte> header)

Parameters

header ReadOnlySpan<byte>

The first bytes of the file; HeaderSize bytes when read from a stream. It can be shorter than the file. For a ZIP file read from a seekable stream, the ZIP central directory follows the first bytes.

Returns

bool

True if the bytes match.