| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 0178001 commit 748d2b4
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -258,6 +258,9 @@ function base64ByteLength(str, bytes) { | |||
| 258 | 258 | ||
| 259 | 259 | ||
| 260 | 260 | function byteLength(string, encoding) { | |
| 261 | + if (string instanceof Buffer) | ||
| 262 | + return string.length; | ||
| 263 | + | ||
| 261 | 264 | if (typeof string !== 'string') | |
| 262 | 265 | string = '' + string; | |
| 263 | 266 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,6 +10,12 @@ assert.equal(Buffer.byteLength(NaN, 'utf8'), 3); | |||
| 10 | 10 | assert.equal(Buffer.byteLength({}, 'raws'), 15); | |
| 11 | 11 | assert.equal(Buffer.byteLength(), 9); | |
| 12 | 12 | ||
| 13 | + // buffer | ||
| 14 | + var incomplete = new Buffer([0xe4, 0xb8, 0xad, 0xe6, 0x96]); | ||
| 15 | + assert.equal(Buffer.byteLength(incomplete), 5); | ||
| 16 | + var ascii = new Buffer('abc'); | ||
| 17 | + assert.equal(Buffer.byteLength(ascii), 3); | ||
| 18 | + | ||
| 13 | 19 | // special case: zero length string | |
| 14 | 20 | assert.equal(Buffer.byteLength('', 'ascii'), 0); | |
| 15 | 21 | assert.equal(Buffer.byteLength('', 'HeX'), 0); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments