| Paste number 15131: | contents-of-file |
| Pasted by: | lemonodor |
| 3 years, 1 week ago | |
| #lisp | |
| Paste contents: |
| (defun contents-of-file (pathname) "Returns a string with the entire contents of the specified file." (with-output-to-string (contents) (with-open-file (in pathname :direction :input) (let* ((buffer-size 4096) (buffer (make-string buffer-size))) (labels ((read-chunks () (let ((size (read-sequence buffer in))) (if (< size buffer-size) (princ (subseq buffer 0 size) contents) (progn (princ buffer contents) (read-chunks)))))) (read-chunks)))))) |
Annotations for this paste:
| Annotation number 1: | like this |
| Pasted by: | jsnell |
| 3 years, 1 week ago | |
| Paste contents: |
| (defun contents-of-file (pathname) "Returns a string with the entire contents of the specified file." (with-output-to-string (contents) (with-open-file (in pathname :direction :input) (let* ((buffer-size 4096) (buffer (make-string buffer-size))) (loop for size = (read-sequence buffer in) do (write-string buffer contents :start 0 :end size) while (= size buffer-size)))))) |