From 547d9708281284d373a96e552263b3533ce82624 Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Sat, 6 Aug 2016 15:16:46 -0700 Subject: [PATCH] Add 'latin1' encoding (alias for 'binary') https://github.com/nodejs/node/commit/54cc7212df320f1e489edf8dbeabb167a7 1cbe67 --- index.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 6d613887..de76c7ad 100644 --- a/index.js +++ b/index.js @@ -351,6 +351,7 @@ Buffer.isEncoding = function isEncoding (encoding) { case 'utf8': case 'utf-8': case 'ascii': + case 'latin1': case 'binary': case 'base64': case 'ucs2': @@ -413,6 +414,7 @@ function byteLength (string, encoding) { for (;;) { switch (encoding) { case 'ascii': + case 'latin1': case 'binary': return len case 'utf8': @@ -486,8 +488,9 @@ function slowToString (encoding, start, end) { case 'ascii': return asciiSlice(this, start, end) + case 'latin1': case 'binary': - return binarySlice(this, start, end) + return latin1Slice(this, start, end) case 'base64': return base64Slice(this, start, end) @@ -753,7 +756,7 @@ function asciiWrite (buf, string, offset, length) { return blitBuffer(asciiToBytes(string), buf, offset, length) } -function binaryWrite (buf, string, offset, length) { +function latin1Write (buf, string, offset, length) { return asciiWrite(buf, string, offset, length) } @@ -815,8 +818,9 @@ Buffer.prototype.write = function write (string, offset, length, encoding) { case 'ascii': return asciiWrite(this, string, offset, length) + case 'latin1': case 'binary': - return binaryWrite(this, string, offset, length) + return latin1Write(this, string, offset, length) case 'base64': // Warning: maxLength not taken into account in base64Write @@ -957,7 +961,7 @@ function asciiSlice (buf, start, end) { return ret } -function binarySlice (buf, start, end) { +function latin1Slice (buf, start, end) { var ret = '' end = Math.min(buf.length, end)