Skip to content

Commit 26a08e6

Browse files
authored
prefer base64urlSlice function, not mutation
1 parent 340c098 commit 26a08e6

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

index.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,7 @@ function slowToString (encoding, start, end) {
535535
return latin1Slice(this, start, end)
536536

537537
case 'base64url':
538+
return base64urlSlice(this, start, end, encoding)
538539
case 'base64':
539540
return base64Slice(this, start, end, encoding)
540541

@@ -947,14 +948,19 @@ Buffer.prototype.toJSON = function toJSON () {
947948
}
948949
}
949950

951+
function base64urlSlice (buf, start, end, encoding) {
952+
if (start === 0 && end === buf.length) {
953+
return base64urlFromBase64(base64.fromByteArray(buf))
954+
}
955+
956+
return base64urlFromBase64(base64.fromByteArray(buf.slice(start, end)))
957+
}
958+
950959
function base64Slice (buf, start, end, encoding) {
951-
let b64
952960
if (start === 0 && end === buf.length) {
953-
b64 = base64.fromByteArray(buf)
954-
} else {
955-
b64 = base64.fromByteArray(buf.slice(start, end))
961+
return base64.fromByteArray(buf)
956962
}
957-
return encoding === 'base64url' ? base64urlFromBase64(b64) : b64
963+
return base64.fromByteArray(buf.slice(start, end))
958964
}
959965

960966
function utf8Slice (buf, start, end) {

0 commit comments

Comments
 (0)