Streaming download, checksum and archive helpers for the gateway's speech assets.
Streaming download, checksum and archive helpers for the gateway's speech assets.
(delete-dir! f)Recursively delete f. Used to clear a staging dir and to replace an
installed one, so it must not care whether f is a file or a tree.
Recursively delete `f`. Used to clear a staging dir and to replace an installed one, so it must not care whether `f` is a file or a tree.
(download! url path {:keys [on-progress headers sha256]})Stream url to path, calling (on-progress pct) (0..99) as bytes land when
the server reports a content length. opts may carry :on-progress,
:headers and :sha256.
Both timeouts are set: a silently stalled socket must FAIL (so the state machine can report :failed and the user can retry) rather than pin the download atom on :downloading forever, which leaves the UI's mic dead.
A body that ENDS EARLY fails, and so does one whose bytes do not hash to
:sha256. That is the integrity check on every speech asset:
a truncated or substituted .onnx or .dylib is still a PRESENT file, so a
caller that only asks .isFile would install it and then abort the JVM on
the next native load. The digest is computed AS the bytes stream past, so
verifying costs no second read and no second copy.
Stream `url` to `path`, calling `(on-progress pct)` (0..99) as bytes land when the server reports a content length. `opts` may carry `:on-progress`, `:headers` and `:sha256`. Both timeouts are set: a silently stalled socket must FAIL (so the state machine can report :failed and the user can retry) rather than pin the download atom on :downloading forever, which leaves the UI's mic dead. A body that ENDS EARLY fails, and so does one whose bytes do not hash to `:sha256`. That is the integrity check on every speech asset: a truncated or substituted `.onnx` or `.dylib` is still a PRESENT file, so a caller that only asks `.isFile` would install it and then abort the JVM on the next native load. The digest is computed AS the bytes stream past, so verifying costs no second read and no second copy.
(extract-tar-bz2! archive-path target-dir)(extract-tar-bz2! archive-path target-dir on-progress)Extract archive-path into target-dir. Decompressing a several-hundred-MB
bzip2 model takes MINUTES, so on-progress (0..99, optional) is driven by how
far the COMPRESSED file has been consumed — read straight off the file
channel, so the copy loop stays a plain read/write and no UI has to sit on a
frozen number.
Extract `archive-path` into `target-dir`. Decompressing a several-hundred-MB bzip2 model takes MINUTES, so `on-progress` (0..99, optional) is driven by how far the COMPRESSED file has been consumed — read straight off the file channel, so the copy loop stays a plain read/write and no UI has to sit on a frozen number.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |