DownloadedFile Class

A buffered, point-in-time snapshot of a downloaded file's bytes that the caller owns.

Returned by IncomingFile.download(). The bytes are already in memory, so the convenience readers here are synchronous and never re-download. Because it is a snapshot, holding one and reusing it is the way to read the same file several ways without re-fetching through the live IncomingFile handle.

Constructor

DownloadedFile(bytes: bytes, content_type: str, filename: str, source_url: str)

Parameters

Name Description
bytes
Required
content_type
Required
filename
Required
source_url
Required

Methods

save_as

Write the already-buffered bytes to a local file path (no re-fetch, unlike IncomingFile.save_as() which streams a fresh download).

text

Decode bytes as UTF-8 (or a provided encoding). No content-type check. Lossy: invalid bytes become the U+FFFD replacement character and never throw. For strict or binary-safe reads, use bytes.

save_as

Write the already-buffered bytes to a local file path (no re-fetch, unlike IncomingFile.save_as() which streams a fresh download).

async save_as(path: str) -> None

Parameters

Name Description
path
Required

text

Decode bytes as UTF-8 (or a provided encoding). No content-type check. Lossy: invalid bytes become the U+FFFD replacement character and never throw. For strict or binary-safe reads, use bytes.

text(encoding: str = 'utf-8') -> str

Parameters

Name Description
encoding
Default value: utf-8

Attributes

bytes

The file bytes, buffered from stream() read to completion.

bytes: bytes

content_type

MIME type resolved from the download response header, or the incoming file's metadata type if the response omits one. Falls back to application/octet-stream when neither provides a type, so this is never empty.

content_type: str

filename

Resolved filename.

filename: str

source_url

The URL the bytes were actually fetched from.

source_url: str