guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Question about an error with ports


From: Olivier Dion
Subject: Re: Question about an error with ports
Date: Thu, 10 Mar 2022 10:05:12 -0500

On Thu, 10 Mar 2022, Zelphir Kaltstahl <zelphirkaltstahl@posteo.de> wrote:

> I have the following questions:
>
> (1) Is the read-from-write-to procedure useful at all, or is there a better 
> way 
> to get all stuff from an input port and output it to an output port, avoiding 
> possibly large string values?

On Linux, there's slice(2) for pipes that does exactly that.

Otherwise, I think this version is a better fit

(define splice
  (lambda (in-port out-port)
    "Read from an IN-PORT and write to OUT-PORT"
    (let loop ([bv (get-bytevector-some in-port)])
      (unless (eof-object? bv)
        (put-bytevector out-port bv)
        (loop (get-bytevector-some in-port))))))

you should not close OUT-PORT.  This break the REPL in my case if using
the `current-output-port`.

-- 
Olivier Dion
Polymtl



reply via email to

[Prev in Thread] Current Thread [Next in Thread]