# Retrieving and verifying files The catalog holds no file content. To use a file, download it from the address in its pointer and check it against the size and hashes the pointer gives. The fields are described in [fields.md](fields.md). ## Steps 1. Choose an address: `uri`, or one from `alt_uris`, which serve the same bytes. `s3://` addresses usually have a public https address in `alt_uris`. `hf://datasets/@/` stands for `https://huggingface.co/datasets//resolve//`. 2. If `access.needs_auth` says that a login, a guestbook or a form is needed, follow the source's procedure first. 3. If the pointer has `range`, request only those bytes with the HTTP header `Range: bytes=-`. The file is that byte range of `uri`, for example one record inside a WARC file, and `size_bytes` equals `length`. 4. Compare the number of bytes with `size_bytes`, unless it is `null` (the source does not publish the size) or `hash_scope` is `registry_manifest` (below). 5. Compute the hashes named in `hashes` and compare every value; `hash_scope` says what they cover (below). Treat a mismatch as a failure; do not substitute another file. 6. If `hashes` is empty (`hash_source` is `computed_on_fetch`), the source publishes no hash: compute your own after download and keep it with the file. [fetch_selected.py](fetch_selected.py), next to this page, follows these steps for every pointer of a selection whose hashes cover the downloaded bytes (`hash_scope` of `file`), byte ranges included; how to run it is in [selecting.md](selecting.md). ## What the hashes cover (`hash_scope`) - `file` (the default when the field is absent): the bytes you downloaded, that is the whole file, or the byte range when the pointer has `range`. - `http_payload`: the range is one gzip-compressed WARC record. Decompress it, remove the WARC and HTTP headers, undo chunked transfer encoding, and hash the HTTP response body. `size_bytes` stays the compressed length of the record. - `api_body`: `uri` returns JSON from an API. Hash the UTF-8 bytes of the field named in `source_meta.api_body_field` (a dotted path in which numbers index lists; `items.0.body` when absent), not the whole response. Non-string values are written with `json.dumps(value, ensure_ascii=False)` before hashing. The path `$` names the whole response body as returned (after gzip decoding), hashed without parsing and reserializing it. When `source_meta.api_body_decode` is `base64`, the field holds the file content as base64 text: decode it and compare size and hashes on the decoded bytes, which are the file. - `html_region`: `uri` is an HTML page with parts that can differ between requests (comments, ratings, text shown only to some readers). Hash only the stable region named in `source_meta.html_region`, not the whole page; `size_bytes` is the size of that region. For `ctftime_page`, working on the page bytes: take the span from the first `