Skip to content

Commit 5b3b0b1

Browse files
committed
wrap lines of base64 in chunks
1 parent 9cb52e6 commit 5b3b0b1

File tree

3 files changed

+1984
-2
lines changed

3 files changed

+1984
-2
lines changed

lib/libbase64.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,19 @@ function wrap(str, lineLength) {
4343
return str;
4444
}
4545

46-
return str.replace(new RegExp('.{' + lineLength + '}', 'g'), '$&\r\n').trim();
46+
let result = [];
47+
let pos = 0;
48+
let chunkLength = lineLength * 1024;
49+
while (pos < str.length) {
50+
let wrappedLines = str
51+
.substr(pos, chunkLength)
52+
.replace(new RegExp('.{' + lineLength + '}', 'g'), '$&\r\n')
53+
.trim();
54+
result.push(wrappedLines);
55+
pos += chunkLength;
56+
}
57+
58+
return result.join('\r\n').trim();
4759
}
4860

4961
/**

0 commit comments

Comments
 (0)