mirror of
https://github.com/revng/revng
synced 2026-06-21 14:07:57 +00:00
b622fe8f19
Implement the `FileProvider` interface, this allows pipes to request files given a `FileRequest` (hash and optional size/name).
24 lines
753 B
Python
24 lines
753 B
Python
#
|
|
# This file is distributed under the MIT License. See LICENSE.md for details.
|
|
#
|
|
|
|
from abc import ABC, abstractmethod
|
|
from dataclasses import dataclass, field
|
|
|
|
|
|
@dataclass
|
|
class FileRequest:
|
|
# Hash of the file, this is a hex-encoded SHA256, with all letters lowercase
|
|
hash: str # noqa: A003
|
|
# Name of the file, this is optional but allows fuzzy searching in some cases
|
|
name: str | None = field(default=None)
|
|
# Size (in bytes) of the file, this is optional but allows fuzzy searching
|
|
# in some cases
|
|
size: int | None = field(default=None)
|
|
|
|
|
|
class FileProvider(ABC):
|
|
@abstractmethod
|
|
def get_files(self, requests: list[FileRequest]) -> dict[str, bytes]:
|
|
"""Request files, return a dict <hash> -> <contents>"""
|