Volume io
volume_io
¶
Streaming helpers for moving files in and out of a transient Modal volume
Additional Information
-
Both the server and the
Modalcontainer runtime use the helpers defined here to copy files into or out of a transient per-job ephemeralModal Volume -
This volume is what allows the container to access local files for processing and send back processed files for the server to save locally
-
Each transfer is streamed in chunks and reported through a themed transfer bar, so neither side ever loads a whole multi-GB media file into memory
-
See the
modal_processing.workermodule for more information on this
download_from_volume(volume, vol_fp, local_path, *, desc=None)
¶
Copies the vol_fp file out of a Modal.Volume to local_path
The file is read from the volume in chunks (never loaded whole into memory) while a themed transfer bar reports the progress. The destination's parent directory is created if missing. The stream lands on a uniquely named temporary sibling and is atomically renamed into place, so a reader (and the Modal-host volume syncer) never sees a partially written file. The temporary is removed on failure
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
volume
|
Volume
|
The volume to read from |
required |
vol_fp
|
str
|
The file's path inside the volume |
required |
local_path
|
str | PathLike[str]
|
The local destination file |
required |
desc
|
str | None
|
Optional bar label. Defaults to
|
None
|
Returns:
| Type | Description |
|---|---|
Path
|
The local destination path |
Raises:
| Type | Description |
|---|---|
ModalVolumeError
|
If the download fails |
upload_to_volume(volume, local_path, vol_fp, *, desc=None)
¶
Stream a local file into a Modal.Volume under the vol_fp key
The file is read from disk in chunks (never loaded whole into memory) while a themed transfer bar reports the progress
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
volume
|
Volume
|
The modal volume to upload into |
required |
local_path
|
str | PathLike[str]
|
The local file to upload |
required |
vol_fp
|
str
|
The destination path inside the volume |
required |
desc
|
str | None
|
Optional bar label. Defaults to
|
None
|
Raises:
| Type | Description |
|---|---|
ModalVolumeError
|
If the source is missing or the upload fails |