Comments (4)
The implementation seems to partially support binary output.
For example here:
Line 147 in 74a1027
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:
Line 129 in 74a1027
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 )
:
Line 187 in 74a1027
from flexi-streams.
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.
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.
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)
- Support for Java's "modified" UTF-8
- flexi-stream not of type stream on ABCL HOT 4
- Warnings issued when building with SBCL
- flexi-streams.asd defines multiple ASDF system definitions HOT 28
- Probably, an error in octets-to-string HOT 2
- Probably, an error in octets-to-string HOT 10
- How do convert to a string or byte array? HOT 1
- Building with SBCL HOT 1
- flexi-stream-position not updated after read-sequence
- Setting flexi-stream-position has no effect on the next byte read HOT 5
- flexi-stream-position not supported for vector-input-stream
- Undefined STREAM var? HOT 1
- README mentions CL-INTERPOL
- peek-char method of flexi-streams:in-memory-stream HOT 2
- :POSITION/:BOUND broken on current Quicklisp version HOT 12
- string output stream? HOT 9
- Pathname from stream HOT 1
- Poor performance? HOT 16
- Tests broken on SBCL 2.4.4 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flexi-streams.