Skip to content

Commit

Permalink
remote_file.py
Browse files Browse the repository at this point in the history
  • Loading branch information
madsbk committed Aug 12, 2024
1 parent b61e63e commit ed1b7a5
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
3 changes: 2 additions & 1 deletion python/kvikio/kvikio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

from kvikio._lib import buffer, driver_properties # type: ignore
from kvikio._version import __git_commit__, __version__ # noqa: F401
from kvikio.cufile import CuFile, RemoteFile # noqa: F401
from kvikio.cufile import CuFile # noqa: F401
from kvikio.remote_file import RemoteFile # noqa: F401


def memory_register(buf) -> None:
Expand Down
41 changes: 41 additions & 0 deletions python/kvikio/kvikio/remote_file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Copyright (c) 2024, NVIDIA CORPORATION. All rights reserved.
# See file LICENSE for terms.

from __future__ import annotations

from typing import Optional

from typing_extensions import Self

from kvikio._lib import remote_handle # type: ignore
from kvikio.cufile import IOFuture


class RemoteFile:
"""File handle of a remote file"""

def __init__(self, bucket_name: str, object_name: str):
self._handle = remote_handle.RemoteFile.from_bucket_and_object(
bucket_name, object_name
)

@classmethod
def from_url(cls, url: str) -> Self:
ret = object.__new__(cls)
ret._handle = remote_handle.RemoteFile.from_url(url)
return ret

def __enter__(self) -> RemoteFile:
return self

def __exit__(self, exc_type, exc_val, exc_tb) -> None:
pass

def nbytes(self) -> int:
return self._handle.nbytes()

def pread(self, buf, size: Optional[int] = None, file_offset: int = 0) -> IOFuture:
return IOFuture(self._handle.pread(buf, size, file_offset))

def read(self, buf, size: Optional[int] = None, file_offset: int = 0) -> int:
return self.pread(buf, size, file_offset).get()

0 comments on commit ed1b7a5

Please sign in to comment.