Skip to content
scalive
Menu
ConnectingLiveReconnectingOffline
GitHub
t

LiveUploadWriter

trait LiveUploadWriter[State, Result]

Stores chunks received by the Scalive server and produces a typed completed result.

The framework threads the State returned by each successful method into the next lifecycle step. Once complete succeeds, the state is replaced by Result. When the runtime releases a resource it still tracks, state is cleaned with abort and a completed result with discard. A failed method must release any side effects not represented by the last successful state. Framework cleanup is best-effort and cannot run after abrupt process termination, so writers must not rely on it as their only recovery mechanism.

Type parameters

State

private in-progress writer state

Result

completed resource or value exposed to consume callbacks

Exported from scalive.upload.LiveUploadWriter. View source (scalive/api/src/scalive/upload/LiveUpload.scala:523-571)

Methods6

abort

def abort(state: State, reason: LiveUploadAbortReason): zio.package.Task[Unit]

Releases an initialized state that did not produce a completed result.

This method is not called when initialization never produced a state. Cleanup failures are logged and otherwise ignored by lifecycle cleanup. If writeChunk fails after acquiring resources not represented by its input state, that failed call must release them itself.

Exported from scalive.upload.LiveUploadWriter.abort. View source (scalive/api/src/scalive/upload/LiveUpload.scala:552-552)

complete

def complete(state: State): zio.package.Task[Result]

Finalizes an entry when the upload protocol considers it complete and returns its result.

A browser progress message can request completion, so implementations should validate their state rather than assuming client-reported size or progress proves that all expected content was written.

Exported from scalive.upload.LiveUploadWriter.complete. View source (scalive/api/src/scalive/upload/LiveUpload.scala:544-544)

discard

def discard(result: Result): zio.package.Task[Unit]

Releases a completed result abandoned while it is still framework-owned.

For results still tracked by the runtime, this includes cancellation, disallow, component removal, and socket shutdown. It is not called after a consume callback returns Consume. Cleanup failures are logged and otherwise ignored by lifecycle cleanup.

Exported from scalive.upload.LiveUploadWriter.discard. View source (scalive/api/src/scalive/upload/LiveUpload.scala:561-561)

init

def init(client: UploadClientMetadata): zio.package.Task[State]

Initializes writer state when the browser joins the hosted upload channel.

client is entirely client-controlled and must be validated before it influences storage or authorization decisions.

Exported from scalive.upload.LiveUploadWriter.init. View source (scalive/api/src/scalive/upload/LiveUpload.scala:529-529)

metadata

def metadata(result: Result): zio.json.ast.Json.Obj

Produces application metadata stored with the completed result.

The default is an empty object. Implementations should be pure and non-throwing because this is evaluated immediately after complete succeeds.

Exported from scalive.upload.LiveUploadWriter.metadata. View source (scalive/api/src/scalive/upload/LiveUpload.scala:568-570)

writeChunk

def writeChunk(data: zio.Chunk[Byte], state: State): zio.package.Task[State]

Writes one received chunk and returns the state to use for the next chunk.

Chunk boundaries are a transport detail and must not be used as a content or authorization boundary. The writer remains responsible for its resource and content constraints.

Exported from scalive.upload.LiveUploadWriter.writeChunk. View source (scalive/api/src/scalive/upload/LiveUpload.scala:536-536)