From: Feross Aboukhadijeh Date: Sat, 6 Aug 2016 22:16:46 +0000 (-0700) Subject: Add 'latin1' encoding (alias for 'binary') X-Git-Url: https://zoso.dev/?a=commitdiff_plain;h=547d9708281284d373a96e552263b3533ce82624;p=buffer.git Add 'latin1' encoding (alias for 'binary') https://github.com/nodejs/node/commit/54cc7212df320f1e489edf8dbeabb167a7 1cbe67 --- diff --git a/index.js b/index.js index 6d61388..de76c7a 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)