-
-
Notifications
You must be signed in to change notification settings - Fork 747
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is position used in pipe? #2352
Comments
Yes, it does seem like position isn't needed. However if we're adding the ability to pipe strings then maybe it would actually be needed for that? |
Looking at this, while keep position we don't actually send 3 arguments to We could send the extra 3 arguments and could then implement a It looks like it might be good to update the error messages, but to keep |
I think we should instead make a wrapper object for string that can handle the reading. That way The Stream class doesn't need much, it could be something like this: class Stream {
constructor(src){
this.src = src;
this.position = 0;
}
read(length){
return this.src.substring(this.position, Math.min(this.position += length, this.src.length));
}
} |
Just done - that ended up being nice and easy. Not sure if there's any other object type it's worth wrapping that way too, like Arrays... |
Based on #2350 (comment) I wanted to see what it would take to implement piping of strings. But looking at the pipe code I don't really follow how it works. There is a
position
number on the pipe object, but it's not actually used anywhere:Espruino/src/jswrap_pipe.c
Lines 117 to 131 in 9d13de0
read
is only given a chunkSize, andwrite
is given the buffer. It seams like the readable and writable streams handle their positioning themselves.If I understand this correctly then
position
and all references to it (in the error messages) can be removed.The text was updated successfully, but these errors were encountered: