megfile.http_path module

class megfile.http_path.HttpPath(path: Union[str, BasePath, PathLike], *other_paths: Union[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_concurrency: Optional[int] = None, max_buffer_size: int = 134217728, forward_ratio: Optional[float] = None, block_size: int = 8388608, **kwargs) Union[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 ‘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_concurrency – Max download thread number, None by default

  • max_buffer_size – Max cached buffer size in memory, 128MB by default

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

Returns:

BytesIO initialized 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: Union[str, BasePath, PathLike], *other_paths: Union[str, BasePath, PathLike])[source]

Bases: HttpPath

protocol = 'https'