mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-05-21 14:49:18 +02:00
Adding port->bytevector.
This commit is contained in:
parent
31aaaef062
commit
978aed4f60
2 changed files with 8 additions and 1 deletions
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue