diff options
| author | ckonstanski <carlos.konstanski@olo.com> | 2024-05-26 14:20:05 -0600 |
|---|---|---|
| committer | ckonstanski <carlos.konstanski@olo.com> | 2024-05-26 14:20:05 -0600 |
| commit | 49d5274a06a6a8bd7f05a5ed3d5679253d5a1f0a (patch) | |
| tree | 670ae0e6810cbcf457d31e55ce0b2b92d81e5e1a | |
| parent | 2f59c22487ed9b8d17a42259e5c697e5821586d6 (diff) | |
add file-as-base64 function
| -rw-r--r-- | org-ckons-file.asd | 2 | ||||
| -rw-r--r-- | src/file.lisp | 6 |
2 files changed, 7 insertions, 1 deletions
diff --git a/org-ckons-file.asd b/org-ckons-file.asd index c5467f1..9504761 100644 --- a/org-ckons-file.asd +++ b/org-ckons-file.asd @@ -17,7 +17,7 @@ :depends-on ,(eval depends-on) :components ,components)) -(defparameter *quicklisp-packages* '()) +(defparameter *quicklisp-packages* '(cl-base64)) (defparameter *asdf-packages* '(org-ckons-core org-ckons-condition)) (defparameter *all-packages* (append *quicklisp-packages* *asdf-packages*)) diff --git a/src/file.lisp b/src/file.lisp index 363cd08..8f0a389 100644 --- a/src/file.lisp +++ b/src/file.lisp @@ -70,6 +70,12 @@ line at a time." (format stream pattern byte)))) (string-downcase hex))) +(defun file-as-base64 (filename) + (let ((bytes (make-array '(0) :element-type '(unsigned-byte 8) :fill-pointer 0 :adjustable t))) + (loop for byte in (file-as-bytes filename) + do (vector-push-extend byte bytes)) + (cl-base64:usb8-array-to-base64-string bytes))) + (defun get-mime-type (filename) (car (org-ckons-core::shell-wrapper (format nil "file --mime-type ~a | awk -F': ' '{print $2}'" filename)))) |
