Giter Site home page Giter Site logo

Comments (12)

mfiano avatar mfiano commented on August 19, 2024

Can reproduce. It seems position is always 0 and bound is interpreted as the relative offset from the supplied position. Seems a little strange, and doesn't align with the docstring.

from flexi-streams.

stassats avatar stassats commented on August 19, 2024

I don't see where this behavior is documented anywhere.

from flexi-streams.

phoe avatar phoe commented on August 19, 2024

https://edicl.github.io/flexi-streams/#make-flexi-stream

Zrzut ekranu z 2021-03-25 21-46-12

position is the initial octet position of the stream and must only be provided for input streams, the default is 0. bound should be NIL (the default) or an integer and must only be provided for input streams. If the octet position of the stream has gone beyond this bound, the stream will behave as if no more input is available.

from flexi-streams.

stassats avatar stassats commented on August 19, 2024

It doesn't say that it moves the position of the underlying stream.

from flexi-streams.

phoe avatar phoe commented on August 19, 2024

What does it do, then, and why does it interact with bound in the way it does?

from flexi-streams.

stassats avatar stassats commented on August 19, 2024

It gets incremented.

from flexi-streams.

phoe avatar phoe commented on August 19, 2024

OK, let me approach the problem from another way.

I have a file with contents #(0 1 2 3 4 5 6 7 8 9). I would like to get an open stream to that file that will only refer to the "slice" #(2 3 4 5) inside that file (e.g. when read-sequence is called on the stream). What is the canonical way of achieving that via flexi-streams? Does it involve the :bound and :position arguments?

from flexi-streams.

stassats avatar stassats commented on August 19, 2024

Call FILE-POSITION beforehand.

from flexi-streams.

stassats avatar stassats commented on August 19, 2024

Or even (setf flexi:stream-file-position)

from flexi-streams.

phoe avatar phoe commented on August 19, 2024

So like the following, I assume:

CL-USER> (with-open-file (stream #p"/tmp/bytes" :element-type '(unsigned-byte 8)
                                                :direction :input)
           (let ((flexi-stream (flex:make-flexi-stream stream :position 4 :bound 8
                                                              :element-type '(unsigned-byte 8)))
                 (output (make-array 10 :initial-element 0)))
             (file-position stream 4)
             (read-sequence output flexi-stream)
             output))
#(4 5 6 7 0 0 0 0 0 0)

OK, this works. Thanks.

(flex:stream-file-position is unexported; file-position works just fine though.)

from flexi-streams.

stassats avatar stassats commented on August 19, 2024

it's actually from gray streams. So file-position will dispatch to it keeping everything in sync.

from flexi-streams.

stassats avatar stassats commented on August 19, 2024

Assuming you call it (file-position flexi-stream 4), no need to supply :position 4 then.

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.