Skip to content

Commit

Permalink
Add Buffer.byteLength docs
Browse files Browse the repository at this point in the history
  • Loading branch information
creationix authored and ry committed Apr 19, 2010
1 parent ff64094 commit 60de863
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions doc/api.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,18 @@ Node supports 3 string encodings. UTF-8 (`'utf8'`), ASCII (`'ascii'`), and
Binary (`'binary'`). `'ascii'` and `'binary'` only look at the first 8 bits
of the 16bit JavaScript string characters.

### Buffer.byteLength(string, encoding)
Gives the actual byte length of a string. This is not the same as
`String.prototype.length` since that returns the number of *characters* in a
string.

// Takes in a UTF8 string, gives back a buffer
function stringToBuffer(string) {
var buffer = new Buffer(Buffer.byteLength(string));
buffer.utf8Write(string);
return buffer;
};

### new Buffer(size)
Allocates a new buffer of `size` octets.

Expand Down

0 comments on commit 60de863

Please sign in to comment.