root/file-utils.scm

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
(define-module (file-utils)
  #:export (get-file-contents))

(define (get-file-contents file-path)
  (define (read-step)
    (let ((c (read-char)))
      (if (eof-object? c)
          (current-output-port)
          (begin
            (display c)
            (read-step)))))
  (with-input-from-file file-path
    (lambda ()
      (with-output-to-string
        (lambda ()
          (set-port-encoding! (current-output-port) "utf-8")
          (read-step))))))