Skip to content

A function to read file from Amazon S3, URLs, or local paths#162

Merged
CluckRookie merged 3 commits intoCambioML:mainfrom
CluckRookie:main
Feb 3, 2024
Merged

A function to read file from Amazon S3, URLs, or local paths#162
CluckRookie merged 3 commits intoCambioML:mainfrom
CluckRookie:main

Conversation

@CluckRookie
Copy link
Contributor

No description provided.

@notion-workspace
Copy link

Copy link
Collaborator

@CambioML CambioML left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

approve with minor comment

obj = s3.get_object(Bucket=bucket_name, Key=file_path)
data = obj["Body"].read()
return data.decode() if mode == "r" else data
if source.startswith("http://") or source.startswith("https://"):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: elif might be better.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +55 to +57
# Read file from local filesystem
with open(source, mode) as file:
return file.read()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: else

Comment on lines +10 to +14
Parameters:
- source (str): The path to the file. This can be an S3 bucket path (s3://bucket_name/file_path),
a URL (http:// or https://), or a local file path.
- mode (str): The mode in which to open the file. Use 'r' for text mode and 'rb' for binary mode.
Default is 'r'.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Args because we we using Google docstring format.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants