This is the mail archive of the
mailing list for the Guile project.
a simple problem
- To: firstname.lastname@example.org
- Subject: a simple problem
- From: "<Brad Knotwell" <email@example.com>
- Date: Mon, 16 Aug 1999 16:50:26 -0700 (PDT)
- Reply-To: firstname.lastname@example.org
This is probably a frequent problem, so I apologize in advance.
I wrote a small program (guile 1.3) to illustrate my problem. I'm
trying to copy from one port to another. I'd hoped to use
read-line/write-line to do so, but it appears that for binary data
there's a problem. However, I thought the 'split option to read-line
could help me work around it.
Interestingly enough, the split flag leads me to copy the correct
number of bytes, but the data is different than I expect. Am I
completely misunderstanding the usage of the split flag and the
difference between display and write-line?
Thanks in advance.
(define in (open-input-file "/var/lib/locatedb"))
(define out (open-output-file "/tmp/b"))
;this works but it __dirt__ slow and doesn't fit the interface I'd
;(define (cp-port in-port out-port)
; (let ((data (read-char in-port)))
; (if (eof-object? data)
; (write-char data out-port)
; (cp-port in-port out-port)))))
;this should work and does copy the correct number of bytes,
;but the bytes written to the output port appear wrong
(define (cp-port in-port out-port)
(let ((data (read-line in-port 'split)))
(if (eof-object? (cdr data))
(display (car data) out-port)
(write-line (car data) out-port)
(cp-port in-port out-port)))))
(cp-port in out)