io/copy: write to a byte-output-stream shim
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.
This commit is contained in:
parent
635cab0e49
commit
65c8072ec8
1 changed files with 8 additions and 0 deletions
|
|
@ -296,6 +296,14 @@
|
||||||
(let ((port (open-file-output-port (path-of output) (file-options no-fail) (buffer-mode block))))
|
(let ((port (open-file-output-port (path-of output) (file-options no-fail) (buffer-mode block))))
|
||||||
(put-bytevector port bv) (close-port port))
|
(put-bytevector port bv) (close-port port))
|
||||||
(jolt-spit output (input-text input)))))
|
(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)))
|
(else (error #f "io/copy: don't know how to write to" output)))
|
||||||
jolt-nil)
|
jolt-nil)
|
||||||
(def-var! "clojure.java.io" "copy" jio-copy)
|
(def-var! "clojure.java.io" "copy" jio-copy)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue