From 67a974f9474866f9beeb1d5b6cad1ca0811a0c86 Mon Sep 17 00:00:00 2001 From: Moises Macia Date: Tue, 17 Mar 2026 21:54:41 +0000 Subject: [PATCH] add detec_format and validate functions --- lib/feed_reader.ex | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/lib/feed_reader.ex b/lib/feed_reader.ex index 828d3c1..d050399 100644 --- a/lib/feed_reader.ex +++ b/lib/feed_reader.ex @@ -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