@@ -254,6 +254,50 @@ class Hint(enum.Enum):
254254 FRONT_ARTICLE = zim.HintKeys.FRONT_ARTICLE
255255
256256
257+ class ContentProvider :
258+ """ ABC in charge of providing the content to add in the archive to the Creator."""
259+ __module__ = writer_module_name
260+ def __init__ (self ):
261+ self .generator = None
262+
263+ def get_size (self ) -> pyint:
264+ """Size of `get_data`'s result in bytes.
265+
266+ Returns:
267+ int: The size of the data in bytes.
268+ """
269+ raise NotImplementedError("get_size must be implemented.")
270+
271+ def feed(self ) -> WritingBlob:
272+ """Blob(s ) containing the complete content of the article.
273+
274+ Must return an empty blob to tell writer no more content has to be written.
275+ Sum(size(blobs )) must be equals to `self.get_size()`
276+
277+ Returns:
278+ WritingBlob: The content blob(s ) of the article.
279+ """
280+ if self.generator is None:
281+ self.generator = self .gen_blob()
282+
283+ try:
284+ # We have to keep a ref to _blob to be sure gc do not del it while cpp is
285+ # using it
286+ self._blob = next(self .generator)
287+ except StopIteration:
288+ self._blob = WritingBlob(" " )
289+
290+ return self._blob
291+
292+ def gen_blob(self ) -> Generator[WritingBlob , None , None]:
293+ """Generator yielding blobs for the content of the article.
294+
295+ Yields:
296+ WritingBlob: A blob containing part of the article content.
297+ """
298+ raise NotImplementedError("gen_blob (ro feed ) must be implemented")
299+
300+
257301class BaseWritingItem:
258302 """
259303 Data to be added to the archive.
@@ -564,49 +608,6 @@ cdef class _Creator:
564608 """
565609 return self._filename
566610
567- class ContentProvider:
568- """ ABC in charge of providing the content to add in the archive to the Creator."""
569- __module__ = writer_module_name
570- def __init__(self):
571- self.generator = None
572-
573- def get_size(self) -> pyint:
574- """ Size of `get_data`' s result in bytes.
575-
576- Returns:
577- int : The size of the data in bytes.
578- """
579- raise NotImplementedError("get_size must be implemented.")
580-
581- def feed(self) -> WritingBlob:
582- """ Blob(s) containing the complete content of the article.
583-
584- Must return an empty blob to tell writer no more content has to be written.
585- Sum(size(blobs)) must be equals to `self .get_size()`
586-
587- Returns:
588- WritingBlob: The content blob(s) of the article.
589- """
590- if self.generator is None:
591- self.generator = self.gen_blob()
592-
593- try:
594- # We have to keep a ref to _blob to be sure gc do not del it while cpp is
595- # using it
596- self._blob = next(self.generator)
597- except StopIteration:
598- self._blob = WritingBlob("")
599-
600- return self._blob
601-
602- def gen_blob(self) -> Generator[WritingBlob, None, None]:
603- """ Generator yielding blobs for the content of the article.
604-
605- Yields:
606- WritingBlob: A blob containing part of the article content.
607- """
608- raise NotImplementedError("gen_blob (ro feed) must be implemented")
609-
610611
611612class StringProvider(ContentProvider):
612613 """ ContentProvider for a single encoded- or - not UTF- 8 string."""
0 commit comments