Adding port->bytevector.

This commit is contained in:
Alex Shinn 2014-03-22 11:15:23 +09:00
parent 31aaaef062
commit 978aed4f60
2 changed files with 8 additions and 1 deletions

View file

@ -2,7 +2,8 @@
(define-library (chibi io) (define-library (chibi io)
(export read-string read-string! read-line write-line (export read-string read-string! read-line write-line
port-fold port-fold-right port-map port-fold port-fold-right port-map
port->list port->string-list port->sexp-list port->string port->list port->string-list port->sexp-list
port->string port->bytevector
file-position set-file-position! seek/set seek/cur seek/end file-position set-file-position! seek/set seek/cur seek/end
make-custom-input-port make-custom-output-port make-custom-input-port make-custom-output-port
make-custom-binary-input-port make-custom-binary-output-port make-custom-binary-input-port make-custom-binary-output-port

View file

@ -225,6 +225,12 @@
(define (port->string in) (define (port->string in)
(string-concatenate (port->list (lambda (in) (read-string 1024 in)) in))) (string-concatenate (port->list (lambda (in) (read-string 1024 in)) in)))
(define (port->bytevector in)
(let ((out (open-output-bytevector)))
(do ((c (read-u8 in) (read-u8 in)))
((eof-object? c) (get-output-bytevector out))
(write-u8 c out))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; custom port utilities ;; custom port utilities