Scoop API

scoop:scoop.http.client:0.1.0

src/download/api.scoop

Selected production source · src/download/api.scoop

1package scoop.http.client
3import scoop.http.HttpField
4import scoop.http.HttpResponseHead
5import scoop.platform.fs.Path
6import scoop.url.Url
8/**
9 * Download publication, buffering, and progress policy. Completion atomically installs the
10 * destination; failures retain the prior destination.
11 */
12public class HttpDownloadOptions internal constructor(
13 /**
14 * Whether atomic publication may replace an existing destination.
15 */
16 public val replaceExisting: Boolean = false,
17 /**
18 * Whether file contents are synchronized before the final commit.
19 */
20 public val syncOnCommit: Boolean = false,
21 /**
22 * The positive byte-buffer size used while streaming to disk.
23 */
24 public val bufferSize: Long = 8192L,
25 /**
26 * Suspend callback for written-byte progress; it participates in cancellation and failure
27 * cleanup.
28 */
29 public val onProgress: suspend (HttpDownloadProgress) -> Unit = suspend { _ -> }
30) {
31 init {
32 if (bufferSize <= 0L)
33 throw IllegalArgumentException(Some("download buffer size must be positive"))
34 }
37/**
38 * A download progress snapshot with current written bytes, known total, and any reused prefix.
39 */
40public class HttpDownloadProgress internal constructor(
41 /**
42 * The final response URL.
43 */
44 public val url: Url,
45 /**
46 * Total bytes present in the download so far, including any reused prefix.
47 */
48 public val bytesWritten: Long,
49 /**
50 * The expected complete size when known.
51 */
52 public val totalBytes: Long?,
53 /**
54 * Bytes retained from a previously validated partial file.
55 */
56 public val resumedBytes: Long = 0L
59/**
60 * A completed download with committed path, final response metadata, total bytes, and
61 * reused-prefix count.
62 */
63public class HttpDownloadResult internal constructor(
64 /**
65 * The committed destination path.
66 */
67 public val path: Path,
68 /**
69 * The final response URL.
70 */
71 public val url: Url,
72 /**
73 * The successful final response head.
74 */
75 public val head: HttpResponseHead,
76 /**
77 * Complete response trailers after body consumption.
78 */
79 public val trailers: Array<HttpField>,
80 /**
81 * The complete committed file byte count.
82 */
83 public val byteCount: Long,
84 /**
85 * Bytes reused from the previous partial download.
86 */
87 public val resumedBytes: Long = 0L