Coder Social home page Coder Social logo

Comments (7)

inexorabletash avatar inexorabletash commented on August 12, 2024

Just decode(). An example using streaming would probably help. e.g. from https://github.com/inexorabletash/text-encoding

  var string = "", decoder = TextDecoder(encoding), buffer;
  while (buffer = next_chunk()) {
    string += decoder.decode(buffer, {stream:true});
  }
  string += decoder.decode(); // finish the stream

from encoding.

hsivonen avatar hsivonen commented on August 12, 2024

OK. The spec algorithm for decode() is very far from making this clear.

from encoding.

annevk avatar annevk commented on August 12, 2024

Note that per the specification you signal EOF by a call to decode() that does not have the stream member set to true. You can still pass in additional input at that point. At what point does the algorithm confuse you?

from encoding.

annevk avatar annevk commented on August 12, 2024

Would the confusion be removed once we make the change I suggested in #13?

from encoding.

hsivonen avatar hsivonen commented on August 12, 2024

The definition of the flags is separate from the algorithm, so it's easy to get confused by thinking that the streaming flag is an algorithm-local variable (as opposed to being a field of the object), since the corresponding JS argument is to the decode method and not to the constructor.

Other than that, I guess the general problem is that the last two top-level steps of the algorithm require examining the implications of the definitions they reference and, thus, the algorithm isn't obvious when taking a look without reading all the definitions and thinking through their implications.

The change suggested in #13 would alleviate the confusion. To remove confusion completely, substep 2 of major step 5 could use an informative note that points out that streamability is based on omitting EOF handling in that step and leaving flags such that the step 1 is skipped on the next call.

from encoding.

hsivonen avatar hsivonen commented on August 12, 2024

Oh, and for authors, it would be helpful to have a usage note that says in the streaming case you call decode 0 to N times with {stream:true} and then once without and if you don't have input for that last call, you should just omit both arguments.

from encoding.

annevk avatar annevk commented on August 12, 2024

Thank you for the clear suggestions @hsivonen! @inexorabletash, I ended up using your example too.

from encoding.

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.