A fix for the PDFReader to handle reading files as bytestrings. The loader already supported that function but there was a small bug related to the fact that it expected a file name to be fetched which is not available when passing a pdf bystring. This PR addresses this. The file name can still be added manually using the extra_info argument.
PDF bytestrings can be useful in case the user wants to load in case a user uses a custom filesystem interface like fsspec
example:
# Create the GCS file system
gcs = fsspec.filesystem('gcs')
# Open and read the PDF file from GCS
with gcs.open(f'{bucket_name}/{file_path}', 'rb') as file:
pdf_content = BytesIO(file.read())
Fixes # (issue)
Type of Change
Please delete options that are not relevant.
[ ] New Loader/Tool
[X] Bug fix / Smaller change
[ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
[ ] This change requires a documentation update
How Has This Been Tested?
I ran the class locally with different file inputs (path to pdf, pdf bytestrings)
Suggested Checklist:
[ ] I have added a library.json file if a new loader/tool was added
[X] I have performed a self-review of my own code
[ ] I have commented my code, particularly in hard-to-understand areas
[ ] I have made corresponding changes to the documentation
[ ] My changes generate no new warnings
[ ] I have added tests that prove my fix is effective or that my feature works
[X] New and existing unit tests pass locally with my changes
[X] I ran make format; make lint to appease the lint gods
Description
A fix for the PDFReader to handle reading files as bytestrings. The loader already supported that function but there was a small bug related to the fact that it expected a file name to be fetched which is not available when passing a pdf bystring. This PR addresses this. The file name can still be added manually using the
extra_info
argument.PDF bytestrings can be useful in case the user wants to load in case a user uses a custom filesystem interface like fsspec
example:
Fixes # (issue)
Type of Change
Please delete options that are not relevant.
How Has This Been Tested?
I ran the class locally with different file inputs (path to pdf, pdf bytestrings)
Suggested Checklist:
make format; make lint
to appease the lint gods