-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
43 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |