if (type === 'number')
length = subject > 0 ? subject >>> 0 : 0
else if (type === 'string') {
- if (encoding === 'base64')
- subject = base64clean(subject)
length = Buffer.byteLength(subject, encoding)
} else if (type === 'object' && subject !== null) { // assume object is array-like
if (subject.type === 'Buffer' && isArray(subject.data))
return arr
}
-var INVALID_BASE64_RE = /[^+\/0-9A-z]/g
+var INVALID_BASE64_RE = /[^+\/0-9A-z\-]/g
function base64clean (str) {
// Node strips out invalid characters like \n and \t from the string, base64-js does not
str = stringtrim(str).replace(INVALID_BASE64_RE, '')
+ // Node converts strings with length < 2 to ''
+ if (str.length < 2) return ''
// Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
while (str.length % 4 !== 0) {
str = str + '='
}
function base64ToBytes (str) {
- return base64.toByteArray(str)
+ return base64.toByteArray(base64clean(str))
}
function blitBuffer (src, dst, offset, length, unitSize) {