sdsc-ordes / gimie

Extract linked metadata from repositories
https://sdsc-ordes.github.io/gimie/
Apache License 2.0
6 stars 2 forks source link

File-like interface to remote resources #70

Closed cmdoret closed 1 year ago

cmdoret commented 1 year ago

Provides a common file-like interface for remote and local files. This will be needed for parsing tasks requiring access to contents of specific files (e.g. license matching).

This PR does the following:

The interface can be used as follows:

from gimie.io import LocalResource, RemoteResource
local = LocalResource("README.md")

url = "https://raw.githubusercontent.com/SDSC-ORD/gimie/main/README.md"
remote = RemoteResource("README.md", url)

def show_contents(resource: Resource):
  """I show what's in a resource, regardless of where it is"""
  print(resource.name + " contains:")
  with resource.open() as reader:
    print(reader.read())

show_contents(local)
show_contents(remote)