Implement a FileStorage Library
You are tasked with implementing a library for managing file storage in a cloud-based application.
The library should allow users to upload, retrieve, and delete files efficiently. Additionally, the library should provide a way to list all files with metadata such as file size and upload timestamp.
Requirements
- Implement a class
FileStoragewith the following methods: upload_file(file_name: str, file_content: bytes) -> str- Uploads a file and returns a unique identifier for the file.
get_file(file_id: str) -> bytes- Retrieves the content of the file corresponding to the given identifier.
delete_file(file_id: str) -> bool- Deletes the file with the given identifier and returns whether the operation was successful.
list_files() -> List[Dict[str, Any]]- Returns a list of all files with metadata. Each file’s metadata should include:
file_id: The unique identifier of the file.file_name: The original name of the file.file_size: The size of the file in bytes.upload_timestamp: The time the file was uploaded.
这道题要求实现一个简洁的文件存储库 `FileStorage`,核心是用哈希表 / 字典维护 `file_id` 到文件内容与元数据的映射。`upload_file` 需要为每个文件生成唯一标识并记录文件名、大小和上传时间;`get_file` 根据 `file_id` 快速取回内容;`delete_file` 删除对应记录并返回是否成功;`list_files` 则按要求返回所有文件的元信息列表。解题重点通常在于设计清晰的数据结构、保证查找和删除的高效性,以及正确维护文件大小和时间戳等元数据。