megfile.http_path module

class megfile.http_path.HttpPath(path: str | BasePath | PathLike, *other_paths: str | BasePath | PathLike)[source]

Bases: URIPath

exists(followlinks: bool = False) bool[source]

Test if http path exists

Parameters:

followlinks (bool, optional) – ignore this parameter, just for compatibility

Returns:

return True if exists

Return type:

bool

getmtime(follow_symlinks: bool = False) float[source]

Get Last-Modified time of the http request on the given http_url path.

If http response header don’t support Last-Modified, will return None

Parameters:

follow_symlinks – Ignore this parameter, just for compatibility

Returns:

Last-Modified time (in Unix timestamp format)

Raises:

HttpPermissionError, HttpFileNotFoundError

getsize(follow_symlinks: bool = False) int[source]

Get file size on the given http_url path.

If http response header don’t support Content-Length, will return None

Parameters:

follow_symlinks – Ignore this parameter, just for compatibility

Returns:

File size (in bytes)

Raises:

HttpPermissionError, HttpFileNotFoundError

open(mode: str = 'rb', *, max_workers: int | None = None, max_buffer_size: int = 134217728, block_forward: int | None = None, block_size: int = 8388608, **kwargs) BufferedReader | HttpPrefetchReader[source]

Open a BytesIO to read binary data of given http(s) url

Note

Essentially, it reads data of http(s) url to memory by requests, and then return BytesIO to user.

Parameters:
  • mode – Only supports ‘r’ or ‘rb’ mode now

  • encoding – encoding is the name of the encoding used to decode or encode the file. This should only be used in text mode.

  • errors – errors is an optional string that specifies how encoding and decoding errors are to be handled—this cannot be used in binary mode.

  • max_workers – Max download thread number, None by default, will use global thread pool with 8 threads.

  • max_buffer_size – Max cached buffer size in memory, 128MB by default. Set to 0 will disable cache.

  • block_forward – How many blocks of data cached from offset position

  • block_size – Size of single block, 8MB by default. Each block will be uploaded or downloaded by single thread.

Returns:

A file-like object with http(s) data

protocol = 'http'
stat(follow_symlinks=True) StatResult[source]

Get StatResult of http_url response, including size and mtime, referring to http_getsize and http_getmtime

Parameters:

follow_symlinks – Ignore this parameter, just for compatibility

Returns:

StatResult

Raises:

HttpPermissionError, HttpFileNotFoundError

class megfile.http_path.HttpsPath(path: str | BasePath | PathLike, *other_paths: str | BasePath | PathLike)[source]

Bases: HttpPath

protocol = 'https'