( ?w . 48) ( ?x . 49) ( ?y . 50) ( ?z . 51) ( ?0 . 52) ( ?1 . 53)
( ?2 . 54) ( ?3 . 55) ( ?4 . 56) ( ?5 . 57) ( ?6 . 58) ( ?7 . 59)
( ?8 . 60) ( ?9 . 61) ( ?+ . 62) ( ?/ . 63)
- ))
+ ))
(defvar base64-alphabet-decoding-vector
(let ((v (make-vector 123 nil))
(setq p (cdr p)))
v))
+(defvar base64-binary-coding-system 'binary)
+
(defun base64-run-command-on-region (start end output-buffer command
&rest arg-list)
- (let ((tempfile nil) status errstring default-process-coding-system)
+ (let ((tempfile nil) status errstring default-process-coding-system
+ (coding-system-for-write base64-binary-coding-system)
+ (coding-system-for-read base64-binary-coding-system))
(unwind-protect
(progn
(setq tempfile (make-temp-name "base64"))
(setq errstring (buffer-string))
(kill-buffer nil)
(cons status errstring)))))
- (condition-case ()
- (delete-file tempfile)
- (error nil)))))
-
-(defun base64-insert-char (char &optional count ignored buffer)
- (condition-case nil
- (progn
- (insert-char char count ignored buffer)
- (fset 'base64-insert-char 'insert-char))
- (wrong-number-of-arguments
- (fset 'base64-insert-char 'base64-xemacs-insert-char)
- (base64-insert-char char count ignored buffer))))
+ (ignore-errors
+ (delete-file tempfile)))))
-(defun base64-xemacs-insert-char (char &optional count ignored buffer)
- (if (or (null buffer) (eq buffer (current-buffer)))
- (insert-char char count)
- (save-excursion
- (set-buffer buffer)
- (insert-char char count))))
+(if (string-match "XEmacs" emacs-version)
+ (defalias 'base64-insert-char 'insert-char)
+ (defun base64-insert-char (char &optional count ignored buffer)
+ (if (or (null buffer) (eq buffer (current-buffer)))
+ (insert-char char count)
+ (with-current-buffer buffer
+ (insert-char char count))))
+ (setq base64-binary-coding-system 'no-conversion))
(defun base64-decode-region (start end)
(interactive "r")
(if base64-decoder-program
(let* ((binary-process-output t) ; any text already has CRLFs
(status (apply 'base64-run-command-on-region
- start end work-buffer
- base64-decoder-program
- base64-decoder-switches)))
+ start end work-buffer
+ base64-decoder-program
+ base64-decoder-switches)))
(if (not (eq status t))
(error "%s" (cdr status))))
(goto-char start)
((> (skip-chars-forward base64-alphabet end) 0)
(setq lim (point))
(while (< inputpos lim)
- (setq bits (+ bits
+ (setq bits (+ bits
(aref base64-alphabet-decoding-vector
(char-int (char-after inputpos)))))
(setq counter (1+ counter)
(cond ((= counter 4)
(base64-insert-char (lsh bits -16) 1 nil work-buffer)
(base64-insert-char (logand (lsh bits -8) 255) 1 nil
- work-buffer)
+ work-buffer)
(base64-insert-char (logand bits 255) 1 nil
work-buffer)
(setq bits 0 counter 0))
(delete-region (point-max) (point))
(prog1
(buffer-string)
- (kill-buffer (current-buffer)))))
+ (kill-buffer (current-buffer)))))
(fset 'base64-decode-string 'base64-decode)
+(fset 'base64-encode-string 'base64-encode)
(provide 'base64)