mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-09-30 09:17:09 +08:00
This updates Chai, Karma and Sinon. The breaking changes in Karma 6.0.0 don't affect us. DISABLE_THIRD_PARTY_CHECK=NPM update R=jacktfranklin@chromium.org Bug: none Change-Id: I77c2d4b1aeb1f0544d56c1f8a37e409a19352bfe Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2692906 Commit-Queue: Tim van der Lippe <tvanderlippe@chromium.org> Reviewed-by: Jack Franklin <jacktfranklin@chromium.org>
47 lines
1.3 KiB
JavaScript
47 lines
1.3 KiB
JavaScript
const { PACKET_TYPES } = require("./commons");
|
|
|
|
const withNativeBlob =
|
|
typeof Blob === "function" ||
|
|
(typeof Blob !== "undefined" &&
|
|
Object.prototype.toString.call(Blob) === "[object BlobConstructor]");
|
|
const withNativeArrayBuffer = typeof ArrayBuffer === "function";
|
|
|
|
// ArrayBuffer.isView method is not defined in IE10
|
|
const isView = obj => {
|
|
return typeof ArrayBuffer.isView === "function"
|
|
? ArrayBuffer.isView(obj)
|
|
: obj && obj.buffer instanceof ArrayBuffer;
|
|
};
|
|
|
|
const encodePacket = ({ type, data }, supportsBinary, callback) => {
|
|
if (withNativeBlob && data instanceof Blob) {
|
|
if (supportsBinary) {
|
|
return callback(data);
|
|
} else {
|
|
return encodeBlobAsBase64(data, callback);
|
|
}
|
|
} else if (
|
|
withNativeArrayBuffer &&
|
|
(data instanceof ArrayBuffer || isView(data))
|
|
) {
|
|
if (supportsBinary) {
|
|
return callback(data instanceof ArrayBuffer ? data : data.buffer);
|
|
} else {
|
|
return encodeBlobAsBase64(new Blob([data]), callback);
|
|
}
|
|
}
|
|
// plain string
|
|
return callback(PACKET_TYPES[type] + (data || ""));
|
|
};
|
|
|
|
const encodeBlobAsBase64 = (data, callback) => {
|
|
const fileReader = new FileReader();
|
|
fileReader.onload = function() {
|
|
const content = fileReader.result.split(",")[1];
|
|
callback("b" + content);
|
|
};
|
|
return fileReader.readAsDataURL(data);
|
|
};
|
|
|
|
module.exports = encodePacket;
|