Skip to content

Commit

Permalink
Add 'latin1' encoding (alias for 'binary')
Browse files Browse the repository at this point in the history
  • Loading branch information
feross committed Aug 6, 2016
1 parent 6696bb0 commit 547d970
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ Buffer.isEncoding = function isEncoding (encoding) {
case 'utf8':
case 'utf-8':
case 'ascii':
case 'latin1':
case 'binary':
case 'base64':
case 'ucs2':
Expand Down Expand Up @@ -413,6 +414,7 @@ function byteLength (string, encoding) {
for (;;) {
switch (encoding) {
case 'ascii':
case 'latin1':
case 'binary':
return len
case 'utf8':
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 547d970

Please sign in to comment.