From 60de86351ac9264845bc4033eb7e44b9b0c74c6d Mon Sep 17 00:00:00 2001 From: Tim Caswell Date: Mon, 19 Apr 2010 08:17:37 -0500 Subject: [PATCH] Add Buffer.byteLength docs --- doc/api.markdown | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/doc/api.markdown b/doc/api.markdown index 241bc43..2f1abed 100644 --- a/doc/api.markdown +++ b/doc/api.markdown @@ -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. -- 2.7.4