Function: url-data

url-data is an autoloaded and byte-compiled function defined in url-misc.el.gz.

Signature

(url-data URL)

Documentation

Fetch a data URL (RFC 2397).

Source Code

;; Defined in /usr/src/emacs/lisp/url/url-misc.el.gz
;; RFC 2397
;;;###autoload
(defun url-data (url)
  "Fetch a data URL (RFC 2397)."
  (let ((mediatype nil)
	;; The mediatype may need to be hex-encoded too -- see the RFC.
	(desc (url-unhex-string (url-filename url)))
	(encoding "8bit")
	(data nil))
    (save-excursion
      (if (not (string-match "\\([^,]*\\)," desc))
	  (error "Malformed data URL: %s" desc)
	(setq mediatype (match-string 1 desc)
	      data (url-unhex-string (substring desc (match-end 0))))
	(if (and mediatype (string-match ";base64\\'" mediatype))
	    (setq mediatype (substring mediatype 0 (match-beginning 0))
		  encoding "base64"))
	(if (or (null mediatype)
		(eq ?\; (aref mediatype 0)))
	  (setq mediatype (concat "text/plain" mediatype))))
      (set-buffer (generate-new-buffer " *url-data*"))
      (require 'mm-util)
      (mm-disable-multibyte)
      (insert (format "Content-Length: %d\n" (length data))
	      "Content-Type: " mediatype "\n"
	      "Content-Transfer-Encoding: " encoding "\n"
	      "\n")
      (if data (insert data))
      (current-buffer))))