Skip to content

File-like Object

Native support for reading from object stores as a file-like object.

Use obstore.open or obstore.open_async to open files. Writing files in this way is not yet supported.

obstore.open

open(store: ObjectStore, path: str) -> ReadableFile

Open a file object from the specified location.

Parameters:

  • store (ObjectStore) –

    The ObjectStore instance to use.

  • path (str) –

    The path within ObjectStore to retrieve.

Returns:

obstore.open_async async

open_async(store: ObjectStore, path: str) -> AsyncReadableFile

Call open asynchronously, returning a file object with asynchronous operations.

Refer to the documentation for [open][object_store_rs.open].

obstore.ReadableFile

A readable file object with synchronous operations.

close

close() -> None

Close the current file.

This is currently a no-op.

read

read(size: int | None = None) -> Buffer

Read up to size bytes from the object and return them. As a convenience, if size is unspecified or None, all bytes until EOF are returned.

readall

readall() -> Buffer

Read and return all the bytes from the stream until EOF, using multiple calls to the stream if necessary.

readline

readline() -> Buffer

Read a single line of the file, up until the next newline character.

readlines

readlines(hint: int = -1) -> List[Buffer]

Read all remaining lines into a list of buffers

seek

seek(offset: int, whence: int = SEEK_SET) -> int

Change the stream position to the given byte offset, interpreted relative to the position indicated by whence, and return the new absolute position. Values for whence are:

  • os.SEEK_SET or 0: start of the stream (the default); offset should be zero or positive
  • os.SEEK_CUR or 1: current stream position; offset may be negative
  • os.SEEK_END or 2: end of the stream; offset is usually negative

seekable

seekable() -> bool

Return True if the stream supports random access.

tell

tell() -> int

Return the current stream position.

obstore.AsyncReadableFile

A readable file object with asynchronous operations.

close

close() -> None

Close the current file.

This is currently a no-op.

read async

read(size: int | None = None) -> Buffer

Read up to size bytes from the object and return them. As a convenience, if size is unspecified or None, all bytes until EOF are returned.

readall async

readall() -> Buffer

Read and return all the bytes from the stream until EOF, using multiple calls to the stream if necessary.

readline async

readline() -> Buffer

Read a single line of the file, up until the next newline character.

readlines async

readlines(hint: int = -1) -> List[Buffer]

Read all remaining lines into a list of buffers

seek async

seek(offset: int, whence: int = SEEK_SET) -> int

Change the stream position to the given byte offset, interpreted relative to the position indicated by whence, and return the new absolute position. Values for whence are:

  • os.SEEK_SET or 0: start of the stream (the default); offset should be zero or positive
  • os.SEEK_CUR or 1: current stream position; offset may be negative
  • os.SEEK_END or 2: end of the stream; offset is usually negative

seekable

seekable() -> bool

Return True if the stream supports random access.

tell async

tell() -> int

Return the current stream position.