Skip to content

Commit

Permalink
doc
Browse files Browse the repository at this point in the history
  • Loading branch information
e3krisztian committed Aug 8, 2023
1 parent d8c9bbd commit 38764d0
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ class Extractor(abc.ABC):
return []

@abc.abstractmethod
def extract(self, inpath: Path, outdir: Path):
def extract(self, inpath: Path, outdir: Path) -> Optional[ExtractResult]:
"""Extract the carved out chunk. Raises ExtractError on failure."""
```

Expand All @@ -526,6 +526,15 @@ Two methods are exposed by this class:
- `extract()`: you must override this function. This is where you'll perform the
extraction of `inpath` content into `outdir` extraction directory

!!! Recommendation

Although it is possible to implement `extract()` with path manipulations,
checks for path traversals, and performing io by using Python libraries
(`os`, `pathlib.Path`), but it turns out somewhat tedious.
Instead we recommend to remove boilerplate and use a helper class
`FileSystem` from [unblob/file_utils.py](https://github.com/onekey-sec/unblob/blob/main/unblob/file_utils.py) which ensures that all file objects are created under
its root.

### DirectoryExtractor class

The `DirectoryExtractor` interface is defined in
Expand All @@ -538,7 +547,7 @@ class DirectoryExtractor(abc.ABC):
return []

@abc.abstractmethod
def extract(self, paths: List[Path], outdir: Path):
def extract(self, paths: List[Path], outdir: Path) -> Optional[ExtractResult]:
"""Extract from a multi file path list.
Raises ExtractError on failure.
Expand All @@ -552,6 +561,11 @@ Two methods are exposed by this class:
- `extract()`: you must override this function. This is where you'll perform the
extraction of `paths` files into `outdir` extraction directory

!!! Recommendation

Similarly to `Extractor`, it is recommended to use the `FileSystem` helper class to
implement `extract`.

### Example Extractor

Extractors are quite complex beasts, so rather than trying to come up with a
Expand Down

0 comments on commit 38764d0

Please sign in to comment.