Comments (7)
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.
OK. The spec algorithm for decode()
is very far from making this clear.
from encoding.
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.
Would the confusion be removed once we make the change I suggested in #13?
from encoding.
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.
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.
Thank you for the clear suggestions @hsivonen! @inexorabletash, I ended up using your example too.
from encoding.
Related Issues (20)
- End-of-queue during decoding of GB18030 should not mask ASCII characters. HOT 4
- gb18030 encoder using index gb18030 ranges pointer HOT 4
- aria-label usage in BMP coverage table HOT 4
- Bug in TextDecoderStream around processing the end of stream. HOT 1
- Add a static decode and encode method to `TextEncoder` and `TextDecoder` HOT 10
- Shift_JIS decoder HOT 12
- [GB18030] Wrong codepoint at index 7533 HOT 4
- TextDecoderStream: empty Uint8Array should result in an empty string HOT 4
- 7-bit ASCII encoding HOT 3
- The concept of "output encoding" is not described anywhere HOT 5
- Visualization tables has lack of descriptions HOT 2
- Why Big5 index contains unmappable characters? HOT 2
- Consider adding windows-936-2000 as a label for GBK HOT 2
- Preface punctuation
- Reflect changes in GB 18030-2022 HOT 5
- Make encodeInto() throw when given a detached buffer HOT 5
- Ambiguous wording in GB18030 decoder HOT 4
- Reference link wrong in "If ioQueue is empty..." HOT 1
- Fast byteLength() HOT 4
- Throw exception when text encode alloc memory fail.
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 encoding.