Download docs/retrieval.md from Battam/terminal-data-pointers: direct link, hf CLI and curl.
- Browser
- Download file 5.12 kB
-
https://huggingface.co/datasets/Battam/terminal-data-pointers/resolve/main/docs/retrieval.md
- Command line
-
hf download hf://datasets/Battam/terminal-data-pointers/docs/retrieval.md
-
curl -L -o retrieval.md https://huggingface.co/datasets/Battam/terminal-data-pointers/resolve/main/docs/retrieval.md
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.
Steps
- Choose an address:
uri, or one fromalt_uris, which serve the same bytes.s3://addresses usually have a public https address inalt_uris.hf://datasets/<repo>@<revision>/<path>stands forhttps://huggingface.co/datasets/<repo>/resolve/<revision>/<path>. - If
access.needs_authsays that a login, a guestbook or a form is needed, follow the source's procedure first. - If the pointer has
range, request only those bytes with the HTTP headerRange: bytes=<offset>-<offset + length - 1>. The file is that byte range ofuri, for example one record inside a WARC file, andsize_bytesequalslength. - Compare the number of bytes with
size_bytes, unless it isnull(the source does not publish the size) orhash_scopeisregistry_manifest(below). - Compute the hashes named in
hashesand compare every value;hash_scopesays what they cover (below). Treat a mismatch as a failure; do not substitute another file. - If
hashesis empty (hash_sourceiscomputed_on_fetch), the source publishes no hash: compute your own after download and keep it with the file.
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.
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 hasrange.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_bytesstays the compressed length of the record.api_body:urireturns JSON from an API. Hash the UTF-8 bytes of the field named insource_meta.api_body_field(a dotted path in which numbers index lists;items.0.bodywhen absent), not the whole response. Non-string values are written withjson.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. Whensource_meta.api_body_decodeisbase64, 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:uriis an HTML page with parts that can differ between requests (comments, ratings, text shown only to some readers). Hash only the stable region named insource_meta.html_region, not the whole page;size_bytesis the size of that region. Forctftime_page, working on the page bytes: take the span from the first<div class="page-header">up to (not including) the first<h3>Comments</h3>after it, split it on newline bytes, and append the lines after that point that containMDConvert.render(; drop lines that containctftimecanary(any letter case) but notMDConvert.render(, and lines that are empty or only ASCII whitespace; strip trailing ASCII whitespace from each line; join with a newline byte and add one final newline. A page without both markers fails.registry_manifest:uriis a container image manifest in a container registry, addressed by its digest. Get a pull token first (the batch notes say how), requesturiwith that token and anAcceptheader listing the manifest types, and hash the response bytes; the sha256 equals the digest.size_bytesis not the length of the manifest: it is the compressed size of the image layers, which equals the sum oflayers[].sizeinside the manifest.zip_member_deflate: the range is the compressed data of one member of a ZIP archive (the bytes after its local header). Inflate it as raw DEFLATE data (no zlib or gzip header). The result is the file: its size ispayload_size_bytes, its CRC-32 issource_meta.crc32(8 lowercase hex digits), andhashescover it.size_bytesstays the compressed length.
Files inside archives
A pointer with parent_pointer_id and member_path is a file inside an archive that has its own pointer: retrieve and verify the archive, then extract member_path.
When it also has zip_entry, uri is the zip archive and the file can be retrieved alone: request the 30-byte local file header at local_header_offset, read the file name length (bytes 26-27) and extra field length (bytes 28-29), request compressed_size bytes right after them, decompress (compression_method 0 is stored, 8 is raw deflate), and compare the length with size_bytes and the CRC32 with hashes.crc32.
Source notes and the manifests themselves
Each collection.json adds notes for its source under fetch and notes. Its shards list gives the sha256 of every part file of the batch, so the downloaded manifests can be checked too.