Initial commit

This commit is contained in:
2026-09-21 21:06:49 +07:00
commit 261233564c
20 changed files with 2146 additions and 0 deletions

27
idp_service/webhdfs.py Normal file
View File

@@ -0,0 +1,27 @@
"""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)