History

Compress model and texture file data in multipart/form-data

A compress() method is added to the JavaScript ArrayBuffer object.

David Rowe committed 12 years ago

Commit 287e3d61 parent 5a5bbfd3 files · +21 −3Browse files

Showing the changes to libraries/script-engine/src/ArrayBufferPrototype.cpp (1 of 3 files). Show all

Unified · Split

libraries/script-engine/src/ArrayBufferPrototype.cpp+15−0
@@ -14,6 +14,9 @@ · 13 unmodified lines
1414 #include "ArrayBufferClass.h"
1515 #include "ArrayBufferPrototype.h"
1616
17+static const int QCOMPRESS_HEADER_POSITION = 0;
18+static const int QCOMPRESS_HEADER_SIZE = 4;
19+
1720 Q_DECLARE_METATYPE(QByteArray*)
1821
1922 ArrayBufferPrototype::ArrayBufferPrototype(QObject* parent) : QObject(parent) {
@@ -43,6 +46,18 @@ QByteArray ArrayBufferPrototype::slice(qint32 begin) const { · 23 unmodified lines
4346 return ba->mid(begin, -1);
4447 }
4548
49+QByteArray ArrayBufferPrototype::compress() const {
50+ QByteArray* ba = thisArrayBuffer();
51+
52+ QByteArray buffer = qCompress(*ba);
53+
54+ // Qt's qCompress() default compression level (-1) is the standard zLib compression.
55+ // Here remove Qt's custom header that prevents the data server from uncompressing the files with zLib.
56+ buffer.remove(QCOMPRESS_HEADER_POSITION, QCOMPRESS_HEADER_SIZE);
57+
58+ return buffer;
59+}
60+
4661 QByteArray* ArrayBufferPrototype::thisArrayBuffer() const {
4762 return qscriptvalue_cast<QByteArray*>(thisObject().data());
4863 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t