Savers

Savers manage the storage of downloaded manga pages. This component is essential for defining how and where manga pages are stored, such as on local disk, in a cloud storage bucket, or within a database.

Implementation

To create a custom saver, you should implement the ISaverAdapter ABC. This class mandates the implementation of the save method, which accepts a file path and a File object (containing the file name and data as a BytesIO object) and returns a boolean indicating the success of the operation.

Example

from abc import ABC, abstractmethod
from dataclasses import dataclass
from io import BytesIO
import os

from enma.application.core.interfaces.saver_adapter import File, ISaverAdapter

class CustomSaver(ISaverAdapter):

    @abstractmethod
    def save(self, path: str, file: File) -> bool:
        full_path = os.path.join(path, file.name)
        try:
            with open(full_path, 'wb') as f:
                f.write(file.data.getvalue())
            return True
        except Exception as e:
            print(f"Failed to save file {file.name}: {e}")
            return False

By extending the saver interface, Enma users can tailor the manga storage process to their specific requirements. Whether it's optimizing for speed, handling complex source-specific challenges, or integrating with unique storage solutions, custom savers unlock a high degree of flexibility and control. This extensibility is a cornerstone of Enma's design, ensuring it can adapt to a wide range of manga collection and management scenarios.

Last updated