-
Notifications
You must be signed in to change notification settings - Fork 7.3k
Add an optional maximum length argument to Buffer#write #243
Comments
I think this works as expected now?
If that isn't what you mean, can you post a test case and the expected output? |
Probably, @bzmeteorite's request is to add
|
It's been awhile and I forget the exact details (I wish I had written a test case describing expected functionality, but this issue was mostly a reminder for ryah who said to post an issue, but he never got around to). But I believe what @koichik describes is most likely what I had meant. I believe I found a workaround that implemented this same functionality as well. I can likely find more info later this week and post it here if anyone is still interested. |
See #1361 for a use case: Writing strings that do not use the 0x0 termination pattern. |
Please review. |
Ouch, that's a lot. I guess I can work around it, but please do add a big fat warning to the API doc. |
Oops! This is slower than master:
tuned:
|
Please review (2). |
@koichik bc42d04 fails to apply on master.
|
I hadn't squashed commits, please apply f2ee5aa first. |
Thanks, much better. Still 2% slower but I suppose that's acceptable if it solves a real problem. |
Thanks! |
So here's the little reminder for you ryah.
An optional argument to Buffer#write that accepts the maximum length in bytes to write from the string. Especially useful for when you're writing UTF-8 and you want to cut the string off prematurely, but don't want to break any multibyte characters in half, but should be implemented no matter the encoding (Buffer#write has this functionality if the buffer isn't large enough).
The text was updated successfully, but these errors were encountered: