mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 17:24:24 +02:00
Compress model and texture file data in multipart/form-data
A compress() method is added to the JavaScript ArrayBuffer object.
This commit is contained in:
parent
5a5bbfd612
commit
287e3d6800
3 changed files with 21 additions and 3 deletions
|
@ -184,8 +184,9 @@ var httpMultiPart = (function () {
|
||||||
// - name, string
|
// - name, string
|
||||||
// - name, buffer
|
// - name, buffer
|
||||||
var buffer,
|
var buffer,
|
||||||
|
string,
|
||||||
stringBuffer,
|
stringBuffer,
|
||||||
string;
|
compressedBuffer;
|
||||||
|
|
||||||
if (object.name === undefined) {
|
if (object.name === undefined) {
|
||||||
|
|
||||||
|
@ -217,9 +218,10 @@ var httpMultiPart = (function () {
|
||||||
+ "\r\n";
|
+ "\r\n";
|
||||||
stringBuffer = string.toArrayBuffer();
|
stringBuffer = string.toArrayBuffer();
|
||||||
|
|
||||||
buffer = new Uint8Array(stringBuffer.byteLength + object.buffer.buffer.byteLength);
|
compressedBuffer = object.buffer.buffer.compress();
|
||||||
|
buffer = new Uint8Array(stringBuffer.byteLength + compressedBuffer.byteLength);
|
||||||
buffer.set(new Uint8Array(stringBuffer));
|
buffer.set(new Uint8Array(stringBuffer));
|
||||||
buffer.set(new Uint8Array(object.buffer.buffer), stringBuffer.byteLength);
|
buffer.set(new Uint8Array(compressedBuffer), stringBuffer.byteLength);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,9 @@
|
||||||
#include "ArrayBufferClass.h"
|
#include "ArrayBufferClass.h"
|
||||||
#include "ArrayBufferPrototype.h"
|
#include "ArrayBufferPrototype.h"
|
||||||
|
|
||||||
|
static const int QCOMPRESS_HEADER_POSITION = 0;
|
||||||
|
static const int QCOMPRESS_HEADER_SIZE = 4;
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(QByteArray*)
|
Q_DECLARE_METATYPE(QByteArray*)
|
||||||
|
|
||||||
ArrayBufferPrototype::ArrayBufferPrototype(QObject* parent) : QObject(parent) {
|
ArrayBufferPrototype::ArrayBufferPrototype(QObject* parent) : QObject(parent) {
|
||||||
|
@ -43,6 +46,18 @@ QByteArray ArrayBufferPrototype::slice(qint32 begin) const {
|
||||||
return ba->mid(begin, -1);
|
return ba->mid(begin, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QByteArray ArrayBufferPrototype::compress() const {
|
||||||
|
QByteArray* ba = thisArrayBuffer();
|
||||||
|
|
||||||
|
QByteArray buffer = qCompress(*ba);
|
||||||
|
|
||||||
|
// Qt's qCompress() default compression level (-1) is the standard zLib compression.
|
||||||
|
// Here remove Qt's custom header that prevents the data server from uncompressing the files with zLib.
|
||||||
|
buffer.remove(QCOMPRESS_HEADER_POSITION, QCOMPRESS_HEADER_SIZE);
|
||||||
|
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
|
||||||
QByteArray* ArrayBufferPrototype::thisArrayBuffer() const {
|
QByteArray* ArrayBufferPrototype::thisArrayBuffer() const {
|
||||||
return qscriptvalue_cast<QByteArray*>(thisObject().data());
|
return qscriptvalue_cast<QByteArray*>(thisObject().data());
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@ public:
|
||||||
public slots:
|
public slots:
|
||||||
QByteArray slice(qint32 begin, qint32 end) const;
|
QByteArray slice(qint32 begin, qint32 end) const;
|
||||||
QByteArray slice(qint32 begin) const;
|
QByteArray slice(qint32 begin) const;
|
||||||
|
QByteArray compress() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QByteArray* thisArrayBuffer() const;
|
QByteArray* thisArrayBuffer() const;
|
||||||
|
|
Loading…
Reference in a new issue