12345678910111213141516171819202122232425262728293031 |
- (library (file-reader)
- (export read-file-to-bytevector)
- (import
- (except (rnrs base) let-values)
- (only (guile) lambda* λ
- ;; ports
- call-with-input-file)
- ;; for bytevector operations
- (ice-9 binary-ports)
- (prefix (logging) log:)))
- (define read-file-to-bytevector
- (lambda* (file-location #:key (binary? #f))
- (cond
- ;; Internet knowledge: If the file is binary, it needs to be served
- ;; ISO-8859-1 encoded. Note: Perhaps we can use the existing guess-encoding
- ;; mechanism, instead of figuring things out ourselves?
- [binary?
- (call-with-input-file file-location
- get-bytevector-all
- #:guess-encoding #f
- #:encoding "ISO-8859-1"
- #:binary #t)]
- [else
- (call-with-input-file file-location
- get-bytevector-all
- #:guess-encoding #f
- #:encoding "utf-8"
- #:binary #f)])))
|