r"""Parses a bytes stream and converts its contents into elements. Args: file (IO[bytes]): The file in bytes format to be parsed. **kwargs: Extra kwargs passed to the partition function. Returns: Union[List[Element], None]: List of elements after
(
file: IO[bytes], **kwargs: Any
)
| 156 | |
| 157 | @staticmethod |
| 158 | def parse_bytes( |
| 159 | file: IO[bytes], **kwargs: Any |
| 160 | ) -> Union[List["Element"], None]: |
| 161 | r"""Parses a bytes stream and converts its contents into elements. |
| 162 | |
| 163 | Args: |
| 164 | file (IO[bytes]): The file in bytes format to be parsed. |
| 165 | **kwargs: Extra kwargs passed to the partition function. |
| 166 | |
| 167 | Returns: |
| 168 | Union[List[Element], None]: List of elements after parsing the file |
| 169 | if successful, otherwise `None`. |
| 170 | |
| 171 | Notes: |
| 172 | Supported file types: |
| 173 | "csv", "doc", "docx", "epub", "image", "md", "msg", "odt", |
| 174 | "org", "pdf", "ppt", "pptx", "rtf", "rst", "tsv", "xlsx". |
| 175 | |
| 176 | References: |
| 177 | https://docs.unstructured.io/open-source/core-functionality/partitioning |
| 178 | """ |
| 179 | |
| 180 | from unstructured.partition.auto import partition |
| 181 | |
| 182 | try: |
| 183 | # Use partition to process the bytes stream |
| 184 | elements = partition(file=file, **kwargs) |
| 185 | return elements |
| 186 | except Exception as e: |
| 187 | warnings.warn(f"Failed to partition the file stream: {e}") |
| 188 | return None |
| 189 | |
| 190 | @staticmethod |
| 191 | def clean_text_data( |