@@ -127,7 +127,7 @@ Example:
127127### Class Method: Buffer.concat(list[ , totalLength] )
128128
129129* ` list ` {Array} List of Buffer objects to concat
130- * ` totalLength ` {Number} Total length of the buffers when concatenated
130+ * ` totalLength ` {Number} Total length of the buffers in the list when concatenated
131131
132132Returns a buffer which is the result of concatenating all the buffers in
133133the list together.
@@ -139,6 +139,32 @@ If totalLength is not provided, it is read from the buffers in the list.
139139However, this adds an additional loop to the function, so it is faster
140140to provide the length explicitly.
141141
142+ Example: build a single buffer from a list of three buffers:
143+
144+ var buf1 = new Buffer(10);
145+ var buf2 = new Buffer(14);
146+ var buf3 = new Buffer(18);
147+
148+ buf1.fill(0);
149+ buf2.fill(0);
150+ buf3.fill(0);
151+
152+ var buffers = [buf1, buf2, buf3];
153+
154+ var totalLength = 0;
155+ for (var i = 0; i < buffers.length; i++) {
156+ totalLength += buffers[i].length;
157+ }
158+
159+ console.log(totalLength);
160+ var bufA = Buffer.concat(buffers, totalLength);
161+ console.log(bufA);
162+ console.log(bufA.length);
163+
164+ // 42
165+ // <Buffer 00 00 00 00 ...>
166+ // 42
167+
142168### Class Method: Buffer.compare(buf1, buf2)
143169
144170* ` buf1 ` {Buffer}
0 commit comments