Giter Site home page Giter Site logo

Comments (4)

avodonosov avatar avodonosov commented on July 1, 2024

The implementation seems to partially support binary output.
For example here:

(when (and (vectorp sequence)

It seems, if the sequence you try to write was an array with integer element type, the output would work.

Also the docstring of that function:

An optimized version which uses a buffer underneath. The function
can accepts characters as well as octets and it decides what to do
based on the element type of the sequence (if possible) or on the
individual elements, i.e. you can mix characters and octets in
SEQUENCE if you want. Whether that really works might also depend on
your Lisp, some of the implementations are more picky than others."

Speaking of mixing the chars and octets in the sequence, the code seems to only support it for lists:

(list (iterate (write-object (nth index sequence))))))

For other input sequences, the code applies to every element a @body of code supplied as a parameter. See two lines above.

The body is expected to get the current element using char-getter symbol macro. And the actual bodies unconditionally pass the element to (char-code ):

(let ((octet (char-code char-getter)))

from flexi-streams.

informatimago avatar informatimago commented on July 1, 2024

Ok. Thank you for the answer.
Inded, when passing a (vector octet) it works, (vector T) are expected to contain only characters.

I find it regretable that libraries impose such restrictions, given that CL itself doesn't.

(with-open-file (out "/tmp/binary.out" :direction :output :element-type '(unsigned-byte 8) :if-does-not-exist :create :if-exists :supersede)
  (write-sequence #(65 66 67 68) out)
  (let ((buffer (make-array 4 :element-type '(or null string integer)
                              :initial-contents '(69 70 71 72))))
    (write-sequence buffer out)))
;; --> #(69 70 71 72)

(with-open-file (input "/tmp/binary.out" :element-type 'character)
  (read-line input))
;; --> "ABCDEFGH"
;;     t

so you may want to keep the issue to allow vectors of any type of element, as long as the contents is acceptable, or reject it (and close it).

For now I have a workaround, that makes it more costly to use flexi-stream: I just have to copy the data to temporary vector of octet buffers.

Thank you.

from flexi-streams.

avodonosov avatar avodonosov commented on July 1, 2024

If anything, I am not a maintainer, just a subscribed user. Contributed some fixes in the past, so curious to look at issues sometimes.

from flexi-streams.

avodonosov avatar avodonosov commented on July 1, 2024

So, in short, the issue is: flexi-streams, for input arrays whose element-type is not explicitly binary, always assumes characters. You want it instead to look at the stream element type of the flexi stream itself. Right?

That may be reasonable, especially that CLHS entry for write-sequence mentions stream element type in a way that may be interpretted to suggest such an aporoach:

Might signal an error of type type-error if an element of the bounded sequence is not a member of the stream element type of the stream.

But changing flexi-streams this way will break compatibility: somebody who was successfully performing character output on flexi-stream with element type octet will suddenly get a failure.

The most flexible would be to look at the actual type of every element, as it is currently implemented for lists, but I suppose that was avoided for arrays in a quest for higher performance.

from flexi-streams.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.