Function: eca--url-retrieve-download-file
eca--url-retrieve-download-file is a natively compiled function
defined in eca-process.el.
Signature
(eca--url-retrieve-download-file &key URL PATH ON-DONE ON-ERROR)
Documentation
Downloads async a file from URL to PATH via url-retrieve.
Calls ON-DONE when done. On failure calls ON-ERROR with the error when provided, otherwise signals it. Workaround for `url-copy-file` that has issues with macos async threads. https://github.com/emacs-lsp/lsp-mode/issues/4746#issuecomment-2957183423
Source Code
;; Defined in /nix/store/jklqzw6pzz6j4jrbv8wy0iwgi7jlrbld-emacs-packages-deps/share/emacs/site-lisp/elpa/eca-20260928.1827/eca-process.el
(cl-defun eca--url-retrieve-download-file (&key url path on-done on-error)
"Downloads async a file from URL to PATH via `url-retrieve'.
Calls ON-DONE when done. On failure calls ON-ERROR with the error
when provided, otherwise signals it.
Workaround for `url-copy-file` that has issues with macos async threads.
https://github.com/emacs-lsp/lsp-mode/issues/4746#issuecomment-2957183423"
(url-retrieve
url
(lambda (status)
(let ((resp-buf (current-buffer)))
(unwind-protect
(condition-case err
(progn
(when-let ((error-data (plist-get status :error)))
(error "%s" error-data))
(let ((coding-system-for-write 'binary)
(buffer-file-coding-system 'binary))
(goto-char (point-min))
(unless (re-search-forward "\r?\n\r?\n" nil t)
(error "Failed to parse HTTP response for download"))
(write-region (point) (point-max) path nil 'silent)
(funcall on-done)))
(error (if on-error
(funcall on-error err)
(signal (car err) (cdr err)))))
(ignore-errors (kill-buffer resp-buf)))))
nil
t))