@@ -80,6 +80,69 @@ Allocates a new buffer containing the given `str`. |
80 | 80 | Returns true if the `encoding` is a valid encoding argument, or false |
81 | 81 | otherwise. |
82 | 82 |
|
| 83 | +### Class Method: Buffer.isBuffer(obj) |
| 84 | + |
| 85 | +* `obj` Object |
| 86 | +* Return: Boolean |
| 87 | + |
| 88 | +Tests if `obj` is a `Buffer`. |
| 89 | + |
| 90 | +### Class Method: Buffer.byteLength(string, [encoding]) |
| 91 | + |
| 92 | +* `string` String |
| 93 | +* `encoding` String, Optional, Default: 'utf8' |
| 94 | +* Return: Number |
| 95 | + |
| 96 | +Gives the actual byte length of a string. `encoding` defaults to `'utf8'`. |
| 97 | +This is not the same as `String.prototype.length` since that returns the |
| 98 | +number of *characters* in a string. |
| 99 | + |
| 100 | +Example: |
| 101 | + |
| 102 | + str = '\u00bd + \u00bc = \u00be'; |
| 103 | + |
| 104 | + console.log(str + ": " + str.length + " characters, " + |
| 105 | + Buffer.byteLength(str, 'utf8') + " bytes"); |
| 106 | + |
| 107 | + // ½ + ¼ = ¾: 9 characters, 12 bytes |
| 108 | + |
| 109 | +### Class Method: Buffer.concat(list, [totalLength]) |
| 110 | + |
| 111 | +* `list` {Array} List of Buffer objects to concat |
| 112 | +* `totalLength` {Number} Total length of the buffers when concatenated |
| 113 | + |
| 114 | +Returns a buffer which is the result of concatenating all the buffers in |
| 115 | +the list together. |
| 116 | + |
| 117 | +If the list has no items, or if the totalLength is 0, then it returns a |
| 118 | +zero-length buffer. |
| 119 | + |
| 120 | +If the list has exactly one item, then the first item of the list is |
| 121 | +returned. |
| 122 | + |
| 123 | +If the list has more than one item, then a new Buffer is created. |
| 124 | + |
| 125 | +If totalLength is not provided, it is read from the buffers in the list. |
| 126 | +However, this adds an additional loop to the function, so it is faster |
| 127 | +to provide the length explicitly. |
| 128 | + |
| 129 | +### buf.length |
| 130 | + |
| 131 | +* Number |
| 132 | + |
| 133 | +The size of the buffer in bytes. Note that this is not necessarily the size |
| 134 | +of the contents. `length` refers to the amount of memory allocated for the |
| 135 | +buffer object. It does not change when the contents of the buffer are changed. |
| 136 | + |
| 137 | + buf = new Buffer(1234); |
| 138 | + |
| 139 | + console.log(buf.length); |
| 140 | + buf.write("some string", 0, "ascii"); |
| 141 | + console.log(buf.length); |
| 142 | + |
| 143 | + // 1234 |
| 144 | + // 1234 |
| 145 | + |
83 | 146 | ### buf.write(string, [offset], [length], [encoding]) |
84 | 147 |
|
85 | 148 | * `string` String - data to be written to buffer |
@@ -155,69 +218,6 @@ Example: copy an ASCII string into a buffer, one byte at a time: |
155 | 218 |
|
156 | 219 | // node.js |
157 | 220 |
|
158 | | -### Class Method: Buffer.isBuffer(obj) |
159 | | - |
160 | | -* `obj` Object |
161 | | -* Return: Boolean |
162 | | - |
163 | | -Tests if `obj` is a `Buffer`. |
164 | | - |
165 | | -### Class Method: Buffer.byteLength(string, [encoding]) |
166 | | - |
167 | | -* `string` String |
168 | | -* `encoding` String, Optional, Default: 'utf8' |
169 | | -* Return: Number |
170 | | - |
171 | | -Gives the actual byte length of a string. `encoding` defaults to `'utf8'`. |
172 | | -This is not the same as `String.prototype.length` since that returns the |
173 | | -number of *characters* in a string. |
174 | | - |
175 | | -Example: |
176 | | - |
177 | | - str = '\u00bd + \u00bc = \u00be'; |
178 | | - |
179 | | - console.log(str + ": " + str.length + " characters, " + |
180 | | - Buffer.byteLength(str, 'utf8') + " bytes"); |
181 | | - |
182 | | - // ½ + ¼ = ¾: 9 characters, 12 bytes |
183 | | - |
184 | | -### Class Method: Buffer.concat(list, [totalLength]) |
185 | | - |
186 | | -* `list` {Array} List of Buffer objects to concat |
187 | | -* `totalLength` {Number} Total length of the buffers when concatenated |
188 | | - |
189 | | -Returns a buffer which is the result of concatenating all the buffers in |
190 | | -the list together. |
191 | | - |
192 | | -If the list has no items, or if the totalLength is 0, then it returns a |
193 | | -zero-length buffer. |
194 | | - |
195 | | -If the list has exactly one item, then the first item of the list is |
196 | | -returned. |
197 | | - |
198 | | -If the list has more than one item, then a new Buffer is created. |
199 | | - |
200 | | -If totalLength is not provided, it is read from the buffers in the list. |
201 | | -However, this adds an additional loop to the function, so it is faster |
202 | | -to provide the length explicitly. |
203 | | - |
204 | | -### buf.length |
205 | | - |
206 | | -* Number |
207 | | - |
208 | | -The size of the buffer in bytes. Note that this is not necessarily the size |
209 | | -of the contents. `length` refers to the amount of memory allocated for the |
210 | | -buffer object. It does not change when the contents of the buffer are changed. |
211 | | - |
212 | | - buf = new Buffer(1234); |
213 | | - |
214 | | - console.log(buf.length); |
215 | | - buf.write("some string", 0, "ascii"); |
216 | | - console.log(buf.length); |
217 | | - |
218 | | - // 1234 |
219 | | - // 1234 |
220 | | - |
221 | 221 | ### buf.copy(targetBuffer, [targetStart], [sourceStart], [sourceEnd]) |
222 | 222 |
|
223 | 223 | * `targetBuffer` Buffer object - Buffer to copy into |
@@ -694,11 +694,8 @@ Note that this is a property on the buffer module returned by |
694 | 694 |
|
695 | 695 | ## Class: SlowBuffer |
696 | 696 |
|
697 | | -This class is primarily for internal use. JavaScript programs should |
698 | | -use Buffer instead of using SlowBuffer. |
| 697 | +Deprecated. SlowBuffer now returns an instance of Buffer. |
699 | 698 |
|
700 | 699 | In order to avoid the overhead of allocating many C++ Buffer objects for |
701 | 700 | small blocks of memory in the lifetime of a server, Node allocates memory |
702 | | -in 8Kb (8192 byte) chunks. If a buffer is smaller than this size, then it |
703 | | -will be backed by a parent SlowBuffer object. If it is larger than this, |
704 | | -then Node will allocate a SlowBuffer slab for it directly. |
| 701 | +in 8Kb (8192 byte) chunks. This is now handled by Smalloc. |