| Paste number 15131: | contents-of-file |
| Pasted by: | lemonodor |
| When: | 3 years, 6 months ago |
| Share: | Tweet this! | http://paste.lisp.org/+BOB |
| Channel: | #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 |
| When: | 3 years, 6 months ago |
| Share: | Tweet this! | http://paste.lisp.org/+BOB#1 |
| 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))))))