[canvaskit] Fix conversion of large images to base64
Bug: skia: Change-Id: I8ab40a382557ae6bd13884ddce027e51ce1fb21f Reviewed-on: https://skia-review.googlesource.com/c/173701 Reviewed-by: Kevin Lubick <kjlubick@google.com>
This commit is contained in:
parent
ac7f23c807
commit
dee08d8f65
@ -17,7 +17,21 @@
|
||||
if (isNode) {
|
||||
return Buffer.from(bytes).toString('base64');
|
||||
} else {
|
||||
return btoa(String.fromCharCode.apply(null, bytes));
|
||||
// From https://stackoverflow.com/a/25644409
|
||||
// because the naive solution of
|
||||
// btoa(String.fromCharCode.apply(null, bytes));
|
||||
// would occasionally throw "Maximum call stack size exceeded"
|
||||
var CHUNK_SIZE = 0x8000; //arbitrary number
|
||||
var index = 0;
|
||||
var length = bytes.length;
|
||||
var result = '';
|
||||
var slice;
|
||||
while (index < length) {
|
||||
slice = bytes.slice(index, Math.min(index + CHUNK_SIZE, length));
|
||||
result += String.fromCharCode.apply(null, slice);
|
||||
index += CHUNK_SIZE;
|
||||
}
|
||||
return btoa(result);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user