Paste number 15131: contents-of-file

Index of paste annotations: 1

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:
Raw Source | XML | Display As
(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:
Raw Source | Display As
(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))))))

Colorize as:
Show Line Numbers
Index of paste annotations: 1

Lisppaste pastes can be made by anyone at any time. Imagine a fearsomely comprehensive disclaimer of liability. Now fear, comprehensively.