Skip to content

API

function bareasgi_static.static_files_provider.add_static_file_provider

Summary

Add static file support.

bareasgi_static.static_files_provider.add_static_file_provider(
app: Application,
source_folder: str,
*,
mount_point: str,
check_source_folder: bool,
index_filename: str | None,
headers: Optional[Headers]
) -> None

Parameters

app: Application

The bareASGI application.

source_folder: str

Where to find the files to serve.

mount_point: str

Where the files should appear on the url. Defaults to '/'.

check_source_folder: bool

If True check the source folder exists. Defaults to True.

index_filename: str | None

An optional index file name. Defaults to None.

headers: Optional[Headers] (optional)

The headers. Defaults to None.

class StaticFilesProvider

Summary

A static file provider.

bareasgi_static.static_files_provider.StaticFilesProvider(
source_folder: str,
*,
path_variable: str | None,
check_source_folder: bool,
index_filename: str | None,
headers: list[tuple[bytes, bytes]] | None
) -> None

Parameters

source_folder: str

Where to find the files to serve.

path_variable: str | None

A path variable to capture the mount point. Defaults to None.

check_source_folder: bool

If True check the source folder exists. Defaults to True.

index_filename: str | None

An optional index file name. Defaults to None.

headers: list[tuple[bytes, bytes]] | None

The headers. Defaults to None.

async function bareasgi_static.file_streaming.file_response

Summary

A utility method to create a file response.

async bareasgi_static.file_streaming.file_response(
request: HttpRequest,
status: int,
path: str,
headers: list[tuple[bytes, bytes]] | None,
content_type: str | None,
filename: str | None,
check_modified: bool | None
) -> HttpResponse

Parameters

request: HttpRequest
status: int

The HTTP status code.

path: str

The path to the file.

headers: list[tuple[bytes, bytes]] | None

The headers. Defaults to None.

content_type: str | None

The content type.. Defaults to None.

filename: str | None (optional)

The filename. Defaults to None.

check_modified: bool | None

If True check for modifications to the file. Defaults to False.

Returns

HttpResponse: The HTTP response

async generator function bareasgi_static.file_streaming.file_writer

Summary

Creates an async iterator to write a file.

async bareasgi_static.file_streaming.file_writer(
path: str,
chunk_size: int
) -> Content

Parameters

path: str

The path of the file to write.

chunk_size: int

The size of each block. Defaults to CHUNK_SIZE.

Yields

Content: An async iterator of bytes.