add detec_format and validate functions

This commit is contained in:
mmacia committed 2026-03-17 21:54:41 +00:00
1 parent 12310ce2dc
commit 67a974f947
1 file changed
+30 -2
+30 -2
View File
@@ -2,7 +2,35 @@ defmodule FeedReader do
@moduledoc """
Standalone feed fetching and parsing library.
The public parsing and fetching APIs will be added incrementally. This
module is the stable namespace for the package.
This module exposes the public format detection and validation helpers.
"""
@typedoc "`:rss`, `:atom`, `:rdf`, `:unknown`, or a custom format's atom ID."
@type format_id :: atom()
@doc """
Detects a format from a bounded binary prefix.
## Options
- `:max_detection_bytes` — `pos_integer()`; default `65_536`; invalid values yield `:unknown`.
- `:formats` — list of modules, checked after RSS, Atom, and RDF in list order; duplicates removed.
Custom modules provide `matches_prefix?/1` and `id/0`.
"""
@spec detect_format(binary(), keyword()) :: format_id()
def detect_format(content, opts \\ []) do
FeedReader.FormatDetector.detect(content, opts)
end
@doc """
Checks only the bounded-prefix signature for a format ID or module.
## Options
- `:max_detection_bytes` — `pos_integer()`, default `65_536`; invalid values yield `false`.
- `:formats` — custom modules used to resolve custom format IDs. Modules provide
`matches_prefix?/1` and `id/0`; passing the format module directly also works.
"""
@spec validate(binary(), atom() | module(), keyword()) :: boolean()
def validate(content, format, opts \\ []) do
FeedReader.FormatDetector.validate(content, format, opts)
end
end