From 65c8072ec8925032185703c203517f843c8ffa2a Mon Sep 17 00:00:00 2001 From: Yogthos Date: Thu, 25 Jun 2026 06:29:57 -0400 Subject: [PATCH] io/copy: write to a byte-output-stream shim MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit io/copy handled file/stream/writer targets but not a host byte-output-stream table (jolt-lang/http-client's ByteArrayOutputStream shim, :jolt/output-stream), erroring 'don't know how to write to'. Dispatch through the shim's .write method, byte-exact for a byte source — the JVM's io/copy writes to any OutputStream. --- host/chez/io-streams.ss | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/host/chez/io-streams.ss b/host/chez/io-streams.ss index 00a843b..3eb9782 100644 --- a/host/chez/io-streams.ss +++ b/host/chez/io-streams.ss @@ -296,6 +296,14 @@ (let ((port (open-file-output-port (path-of output) (file-options no-fail) (buffer-mode block)))) (put-bytevector port bv) (close-port port)) (jolt-spit output (input-text input))))) + ;; a byte-output-stream shim (a host tagged-table with :jolt/output-stream, + ;; e.g. http-client's ByteArrayOutputStream): write through its .write method, + ;; byte-exact for a byte source. + ((and (htable? output) (jolt-truthy? (jolt-ref-get output (keyword "jolt" "output-stream")))) + (let ((bv (input-bytes input))) + (record-method-dispatch output "write" + (list->cseq (list (if bv (make-jolt-array (list->vector (bytevector->u8-list bv)) 'byte) + (input-text input))))))) (else (error #f "io/copy: don't know how to write to" output))) jolt-nil) (def-var! "clojure.java.io" "copy" jio-copy)