Skip to main content

Module download

Module download 

Source
Expand description

Streaming download implementation.

§Protocol

  1. Acquire a scoped resource lock via LockRegistry.
  2. Emit transfer:state { state: running }.
  3. Issue GetObject — obtain content_length and the body ByteStream.
  4. Open <dest>.partial for writing (atomic rename on success).
  5. Stream 256 KB chunks; for each chunk: write to file, increment transferred_bytes, call emit_progress (throttled).
  6. Poll the cancel receiver between chunks.
  7. On cancel: delete .partial, emit Canceled, release lock with Cancel.
  8. On success: rename .partial → final, emit Done, release lock.
  9. On I/O or S3 error: delete .partial, emit Failed, release lock.

§OCP contract

The atomic .partial rename pattern and lock acquire/release sequence are reusable for any downloaded asset. Upload (task 32) acquires the same lock registry with a different op_name.

Constants§

CHUNK_SIZE 🔒
Bytes per read chunk — 256 KB.

Functions§

cleanup_on_error 🔒
Error path: delete .partial (if any), emit Failed, release lock.
download_object
Stream-download key from bucket and write it atomically to dest_path.
handle_cancel 🔒
Cancel path: delete .partial, emit Canceled, release lock.
now_ms 🔒
now_secs 🔒