Skip to content

Make format sniffers initialization public #628

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 2 commits into from
Jul 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import Foundation

/// Sniffs audio formats.
public class AudioFormatSniffer: FormatSniffer {
public init() {}

public func sniffHints(_ hints: FormatHints) -> Format? {
if hints.hasFileExtension("aac") || hints.hasMediaType("audio/aac") {
return Format(specifications: .aac, mediaType: .aac, fileExtension: "aac")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import Foundation

/// Sniffs bitmap formats.
public class BitmapFormatSniffer: FormatSniffer {
public init() {}

public func sniffHints(_ hints: FormatHints) -> Format? {
if hints.hasFileExtension("avif", "avifs") || hints.hasMediaType("image/avif") {
return Format(specifications: .avif, mediaType: .avif, fileExtension: "avif")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import Foundation

/// Sniffs an HTML or XHTML document.
public struct HTMLFormatSniffer: FormatSniffer {
public init() {}

public func sniffHints(_ hints: FormatHints) -> Format? {
if
hints.hasFileExtension("htm", "html") ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import Foundation

/// Sniffs a JSON document.
public struct JSONFormatSniffer: FormatSniffer {
public init() {}

public func sniffHints(_ hints: FormatHints) -> Format? {
if
hints.hasFileExtension("json") ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import Foundation

/// Sniffs an LCP License Document.
public struct LCPLicenseFormatSniffer: FormatSniffer {
public init() {}

public func sniffHints(_ hints: FormatHints) -> Format? {
if
hints.hasFileExtension("lcpl") ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import Foundation

public class LanguageFormatSniffer: FormatSniffer {
public init() {}

public func sniffHints(_ hints: FormatHints) -> Format? {
// JavaScript
if
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import Foundation

/// Sniffs OPDS documents.
public class OPDSFormatSniffer: FormatSniffer {
public init() {}

public func sniffHints(_ hints: FormatHints) -> Format? {
if hints.hasMediaType("application/atom+xml;type=entry;profile=opds-catalog") {
return opds1Entry
Expand Down
2 changes: 2 additions & 0 deletions Sources/Shared/Toolkit/Format/Sniffers/PDFFormatSniffer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import Foundation
///
/// Reference: https://www.loc.gov/preservation/digital/formats/fdd/fdd000123.shtml
public struct PDFFormatSniffer: FormatSniffer {
public init() {}

public func sniffHints(_ hints: FormatHints) -> Format? {
if
hints.hasFileExtension("pdf") ||
Expand Down
2 changes: 2 additions & 0 deletions Sources/Shared/Toolkit/Format/Sniffers/RARFormatSniffer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import Foundation

/// Sniffs a RAR file.
public struct RARFormatSniffer: FormatSniffer {
public init() {}

public func sniffHints(_ hints: FormatHints) -> Format? {
if
hints.hasFileExtension("rar") ||
Expand Down
2 changes: 2 additions & 0 deletions Sources/Shared/Toolkit/Format/Sniffers/RPFFormatSniffer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import Foundation

/// Sniffs a Readium Web Publication package.
public struct RPFFormatSniffer: FormatSniffer {
public init() {}

public func sniffHints(_ hints: FormatHints) -> Format? {
if hints.hasMediaType("application/audiobook+zip") || hints.hasFileExtension("audiobook") {
return audiobook
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import Foundation

/// Sniffs a Readium Web Publication Manifest.
public struct RWPMFormatSniffer: FormatSniffer {
public init() {}

public func sniffHints(_ hints: FormatHints) -> Format? {
if hints.hasMediaType("application/webpub+json") {
return webpub
Expand Down
2 changes: 2 additions & 0 deletions Sources/Shared/Toolkit/Format/Sniffers/XMLFormatSniffer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import Foundation

/// Sniffs an XML document.
public struct XMLFormatSniffer: FormatSniffer {
public init() {}

public func sniffHints(_ hints: FormatHints) -> Format? {
if
hints.hasFileExtension("xml") ||
Expand Down
2 changes: 2 additions & 0 deletions Sources/Shared/Toolkit/Format/Sniffers/ZIPFormatSniffer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import Foundation

/// Sniffs a ZIP file.
public struct ZIPFormatSniffer: FormatSniffer {
public init() {}

public func sniffHints(_ hints: FormatHints) -> Format? {
if
hints.hasFileExtension("zip") ||
Expand Down