"""WebHDFS adapter based on the repository's original hdfs.py example. The original filename shadowed the third-party `hdfs` package it imported. This module streams PDFs to disk instead of loading them fully into memory. """ from pathlib import Path def make_client(url: str): from hdfs import InsecureClient return InsecureClient(url) def read_hdfs_file(hdfs_url: str, file_path: str) -> bytes: """Compatibility with the original read-only example.""" client = make_client(hdfs_url) with client.read(file_path) as reader: return reader.read() def download_pdf(hdfs_url: str, hdfs_path: str, destination: Path, max_bytes: int): client = make_client(hdfs_url) metadata = client.status(hdfs_path) if metadata.get("type") != "FILE" or metadata.get("length", 0) > max_bytes: raise ValueError("HDFS source is not a file or exceeds IDP_MAX_PDF_BYTES") client.download(hdfs_path, str(destination), overwrite=True)