Function: url-file
url-file is an autoloaded and byte-compiled function defined in
url-file.el.gz.
Signature
(url-file URL CALLBACK CBARGS)
Documentation
Handle file: and ftp: URLs.
Aliases
Source Code
;; Defined in /usr/src/emacs/lisp/url/url-file.el.gz
;;;###autoload
(defun url-file (url callback cbargs)
"Handle file: and ftp: URLs."
(let* ((buffer nil)
(uncompressed-filename nil)
(content-type nil)
(content-encoding nil)
(filename (url-file-build-filename url)))
(or filename (error "File does not exist: %s" (url-recreate-url url)))
;; Need to figure out the content-type from the real extension,
;; not the compressed one.
;; FIXME should this regexp not include more extensions; basically
;; everything that url-file-find-possibly-compressed-file does?
(setq uncompressed-filename (if (string-match "\\.\\(gz\\|Z\\|z\\)\\'" filename)
(substring filename 0 (match-beginning 0))
filename))
(setq content-type (mailcap-extension-to-mime
(url-file-extension uncompressed-filename))
content-encoding (pcase (url-file-extension filename)
((or ".z" ".gz") "gzip")
(".Z" "compress")
(".uue" "x-uuencoded")
(".hqx" "x-hqx")
(".bz2" "x-bzip2")
(".xz" "x-xz")
(_ nil)))
(if (file-directory-p filename)
;; A directory is done the same whether we are local or remote
(find-file filename)
(with-current-buffer
(setq buffer (generate-new-buffer " *url-file*"))
(require 'mm-util)
(mm-disable-multibyte)
(setq url-current-object url)
(insert "Content-type: " (or content-type "application/octet-stream") "\n")
(if content-encoding
(insert "Content-transfer-encoding: " content-encoding "\n"))
(if (url-file-host-is-local-p (url-host url))
;; Local files are handled slightly oddly
(if (featurep 'ange-ftp)
(url-file-asynch-callback nil nil
filename
(current-buffer)
callback cbargs)
(url-file-asynch-callback nil nil nil
filename
(current-buffer)
callback cbargs))
;; FTP handling
(let ((new (make-temp-file
(format "url-tmp.%d" (user-real-uid)))))
(if (featurep 'ange-ftp)
(ange-ftp-copy-file-internal filename (expand-file-name new) t
nil t
(list #'url-file-asynch-callback
new (current-buffer)
callback cbargs)
t))))))
buffer))