-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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
Possible Buffer.concat documentation vagueness #3219
Comments
@Martii Are you passing strings to |
@trevnorris |
Here's a console dump of a sample object: [ <Buffer 28 66 75 6e 63 74 69 6f 6e 20 28 29 20 7b 0a 20 20 22 75 73 65 20 73 74 72 69 63 74 22 3b 0a 0a 2f 2f 20 3d 3d 55 73 65 72 53 63 72 69 70 74 3d 3d 0a ... >,
<Buffer 65 20 63 6f 6d 6d 61 73 20 74 6f 20 73 65 70 61 72 61 74 65 20 6b 65 79 73 3c 2f 65 6d 3e 27 2c 0a 20 20 20 20 20 20 20 20 20 20 22 64 65 66 61 75 6c ... > ] |
|
So we probably have an issue then. The change in semantics would be useful to alleviate future confusion in the documentation instead of:
... this is where my confusion is. I'll run some more detailed site tests with 4 Byte Unicode characters until the docs are updated just to be overly-cautious. Thanks for your assistance. :) |
@Martii Think I'm missing something. The var b1 = new Buffer(10);
var b2 = new Buffer(16);
var b3 = new Buffer(18);
var buffers = [b1, b2, b3];
var totalLength = 0;
for (var i = 0; i < buffers.length; i++) {
totalLength = buffers[i].length;
} The for loop is all that happens internally if |
Your example is a little simpler than what I'm creating for a test User Script... ... but that example would be be perfect in the documentation to demonstrate what The words used in the current document use "length" a lot and that particular nomenclature can be confusing compared to String.prototype.length sometimes... it's even mentioned in the doc here to clarify for that particular method. I'm also debug checking the stable release of this API in |
Not a bad thing to be cautious. And a doc PR would be more than welcome. :) |
* Thanks to *node* maintainer for the clarification at nodejs/node#3219 of Buffer length versus character length * Retested on a User Script that contained a lot of Unicode characters in a comment at the beginning then the metadata blocks at the EOF... String.length fails to upload... Buffer length passes on upload with two "chunks" Applies to OpenUserJS#678
Not sure I could cover all use cases since I'm a little new to this particular global object but I can give it a whirl soon. Thanks again for your help. :) |
Submitted... hopefully correctly. Had to do a little "light" reading and match the current doc style of this .md. ;)
Sidenote: missing |
TBH I don't see any reason to think that a function that takes a list of buffers and returns a buffer would have anything to do with strings. Granted, we all experience brain-farts sometimes, but I don't think the documentation can or should guard against all such cases. |
Maybe add a note about when totalLength is less than the total length of the buffers as well? |
@moander |
At the current documentation for
Buffer.concat
the second parameter explanation seems a little vague.On our project we're trying to avoid a possible use case issue and it would be helpful to definitively explain if
totalLength
is Byte length or encoded length e.g. String length, or other... otherwise we may have an issue down the road pop-up.It would be super helpful to clarify this in the documentation. :)
TIA
The text was updated successfully, but these errors were encountered: