mirror of
https://github.com/Armored-Dragon/overte.git
synced 2025-03-11 16:13:16 +01:00
Added Base64 conversion functions
This commit is contained in:
parent
ef4c99b027
commit
c50a4f9cb8
3 changed files with 25 additions and 1 deletions
|
@ -125,3 +125,11 @@ void ScriptManagerScriptingInterface::removeServerEntityScriptMessagesRequest(co
|
|||
_manager->engine()->raiseException("Uuid must not be specified when removeServerEntityScriptMessagesRequest is invoked from entity script");
|
||||
}
|
||||
}
|
||||
|
||||
QString ScriptManagerScriptingInterface::btoa(const QByteArray &binary) {
|
||||
return binary.toBase64();
|
||||
}
|
||||
|
||||
QByteArray ScriptManagerScriptingInterface::atob(const QString &base64) {
|
||||
return QByteArray::fromBase64(base64.toUtf8());
|
||||
}
|
||||
|
|
|
@ -581,6 +581,22 @@ public:
|
|||
Q_INVOKABLE void removeServerEntityScriptMessagesRequest();
|
||||
Q_INVOKABLE void removeServerEntityScriptMessagesRequest(const QUuid& entityID);
|
||||
|
||||
/*@jsdoc
|
||||
* This decodes Base64 string and returns contents as ArrayBuffer.
|
||||
* @function Script.atob
|
||||
* @param {String} base64 - String with Base64-encoded binary data.
|
||||
* @returns {ArrayBuffer} Decoded binary data.
|
||||
*/
|
||||
Q_INVOKABLE QByteArray atob(const QString &base64);
|
||||
|
||||
/*@jsdoc
|
||||
* This encodes ArrayBuffer and returns Base64-encoded string.
|
||||
* @function Script.btoa
|
||||
* @param {ArrayBuffer} binary - Data to be encoded.
|
||||
* @returns {String} String with Base64-encoded binary data.
|
||||
*/
|
||||
Q_INVOKABLE QString btoa(const QByteArray &binary);
|
||||
|
||||
signals:
|
||||
|
||||
/*@jsdoc
|
||||
|
|
|
@ -55,7 +55,7 @@ bool qBytearrayFromScriptValue(const ScriptValue& object, QByteArray &qByteArray
|
|||
if(!v8Value->IsArrayBuffer()) {
|
||||
return false;
|
||||
}
|
||||
v8::Local<v8::ArrayBuffer> arrayBuffer;
|
||||
v8::Local<v8::ArrayBuffer> arrayBuffer = v8::Local<v8::ArrayBuffer>::Cast(v8Value);
|
||||
qByteArray.resize(arrayBuffer->ByteLength());
|
||||
memcpy(qByteArray.data(), arrayBuffer->Data(), arrayBuffer->ByteLength());
|
||||
return true;
|
||||
|
|
Loading…
Reference in a new issue