2020-05-28 16:13:51 +00:00
|
|
|
diff --git a/emsdk/emscripten/tag-1.38.31/src/library_lz4.js b/emsdk/emscripten/tag-1.38.31/src/library_lz4.js
|
2018-09-20 12:25:44 +00:00
|
|
|
index 4c3f583b7..5291002a4 100644
|
2020-05-28 16:13:51 +00:00
|
|
|
--- a/emsdk/emscripten/tag-1.38.31/src/library_lz4.js
|
|
|
|
+++ b/emsdk/emscripten/tag-1.38.31/src/library_lz4.js
|
2018-09-20 12:25:44 +00:00
|
|
|
@@ -5,26 +5,14 @@ mergeInto(LibraryManager.library, {
|
2018-09-17 19:30:25 +00:00
|
|
|
DIR_MODE: {{{ cDefine('S_IFDIR') }}} | 511 /* 0777 */,
|
|
|
|
FILE_MODE: {{{ cDefine('S_IFREG') }}} | 511 /* 0777 */,
|
|
|
|
CHUNK_SIZE: -1,
|
|
|
|
- codec: null,
|
|
|
|
init: function() {
|
|
|
|
- if (LZ4.codec) return;
|
|
|
|
- LZ4.codec = (function() {
|
|
|
|
- {{{ read('mini-lz4.js') }}};
|
|
|
|
- return MiniLZ4;
|
|
|
|
- })();
|
|
|
|
- LZ4.CHUNK_SIZE = LZ4.codec.CHUNK_SIZE;
|
|
|
|
+ LZ4.CHUNK_SIZE = 2048;
|
|
|
|
},
|
|
|
|
loadPackage: function (pack) {
|
|
|
|
LZ4.init();
|
|
|
|
var compressedData = pack['compressedData'];
|
|
|
|
- if (!compressedData) compressedData = LZ4.codec.compressPackage(pack['data']);
|
|
|
|
+ // if (!compressedData) compressedData = LZ4.codec.compressPackage(pack['data']);
|
|
|
|
assert(compressedData.cachedIndexes.length === compressedData.cachedChunks.length);
|
|
|
|
- for (var i = 0; i < compressedData.cachedIndexes.length; i++) {
|
|
|
|
- compressedData.cachedIndexes[i] = -1;
|
|
|
|
- compressedData.cachedChunks[i] = compressedData.data.subarray(compressedData.cachedOffset + i*LZ4.CHUNK_SIZE,
|
|
|
|
- compressedData.cachedOffset + (i+1)*LZ4.CHUNK_SIZE);
|
|
|
|
- assert(compressedData.cachedChunks[i].length === LZ4.CHUNK_SIZE);
|
|
|
|
- }
|
|
|
|
pack['metadata'].files.forEach(function(file) {
|
|
|
|
var dir = PATH.dirname(file.filename);
|
|
|
|
var name = PATH.basename(file.filename);
|
2018-09-20 12:25:44 +00:00
|
|
|
@@ -36,6 +24,12 @@ mergeInto(LibraryManager.library, {
|
|
|
|
end: file.end,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
+ compressedData.buf = Module['_malloc'](LZ4.CHUNK_SIZE);
|
|
|
|
+ for (var i = 0; i < compressedData.cachedIndexes.length; i++) {
|
|
|
|
+ compressedData.cachedIndexes[i] = -1;
|
|
|
|
+ compressedData.cachedChunks[i] = Module['_malloc'](LZ4.CHUNK_SIZE);
|
|
|
|
+ assert(compressedData.cachedChunks[i] !== null)
|
|
|
|
+ }
|
|
|
|
},
|
|
|
|
createNode: function (parent, name, mode, dev, contents, mtime) {
|
|
|
|
var node = FS.createNode(parent, name, mode);
|
2018-09-20 12:29:44 +00:00
|
|
|
@@ -112,6 +106,7 @@ mergeInto(LibraryManager.library, {
|
2018-09-17 19:30:25 +00:00
|
|
|
//console.log('LZ4 read ' + [offset, length, position]);
|
|
|
|
length = Math.min(length, stream.node.size - position);
|
|
|
|
if (length <= 0) return 0;
|
|
|
|
+
|
|
|
|
var contents = stream.node.contents;
|
|
|
|
var compressedData = contents.compressedData;
|
|
|
|
var written = 0;
|
2018-09-21 18:53:13 +00:00
|
|
|
@@ -122,11 +117,14 @@ mergeInto(LibraryManager.library, {
|
2018-09-20 12:25:44 +00:00
|
|
|
var chunkIndex = Math.floor(start / LZ4.CHUNK_SIZE);
|
|
|
|
var compressedStart = compressedData.offsets[chunkIndex];
|
|
|
|
var compressedSize = compressedData.sizes[chunkIndex];
|
|
|
|
+ var startInChunk = start % LZ4.CHUNK_SIZE;
|
|
|
|
+ var endInChunk = Math.min(startInChunk + desired, LZ4.CHUNK_SIZE);
|
|
|
|
var currChunk;
|
|
|
|
if (compressedData.successes[chunkIndex]) {
|
|
|
|
var found = compressedData.cachedIndexes.indexOf(chunkIndex);
|
2018-09-21 18:53:13 +00:00
|
|
|
if (found >= 0) {
|
|
|
|
currChunk = compressedData.cachedChunks[found];
|
|
|
|
+ buffer.set(Module.HEAPU8.subarray(currChunk + startInChunk, currChunk + endInChunk), offset + written);
|
|
|
|
} else {
|
|
|
|
// decompress the chunk
|
|
|
|
compressedData.cachedIndexes.pop();
|
|
|
|
@@ -138,18 +136,19 @@ mergeInto(LibraryManager.library, {
|
2018-09-17 19:30:25 +00:00
|
|
|
Module['decompressedChunks'] = (Module['decompressedChunks'] || 0) + 1;
|
|
|
|
}
|
|
|
|
var compressed = compressedData.data.subarray(compressedStart, compressedStart + compressedSize);
|
|
|
|
- //var t = Date.now();
|
|
|
|
- var originalSize = LZ4.codec.uncompress(compressed, currChunk);
|
|
|
|
- //console.log('decompress time: ' + (Date.now() - t));
|
|
|
|
+ // var t = Date.now();
|
|
|
|
+ // var originalSize = LZ4.codec.uncompress(compressed, currChunk);
|
2018-09-18 17:35:21 +00:00
|
|
|
+ Module.HEAPU8.set(compressed, compressedData.buf);
|
|
|
|
+ var originalSize = Module['_LZ4_decompress_safe'](compressedData.buf, currChunk, compressedSize, LZ4.CHUNK_SIZE);
|
2018-09-17 19:30:25 +00:00
|
|
|
+ // console.log('decompress time: ' + (Date.now() - t));
|
|
|
|
if (chunkIndex < compressedData.successes.length-1) assert(originalSize === LZ4.CHUNK_SIZE); // all but the last chunk must be full-size
|
2018-09-20 12:25:44 +00:00
|
|
|
+ buffer.set(Module.HEAPU8.subarray(currChunk + startInChunk, currChunk + endInChunk), offset + written);
|
2018-09-17 19:30:25 +00:00
|
|
|
}
|
|
|
|
- } else {
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
// uncompressed
|
|
|
|
- currChunk = compressedData.data.subarray(compressedStart, compressedStart + LZ4.CHUNK_SIZE);
|
2018-09-20 12:25:44 +00:00
|
|
|
+ buffer.set(compressedData.data.subarray(compressedStart + startInChunk, compressedStart + endInChunk), offset + written);
|
2018-09-17 19:30:25 +00:00
|
|
|
}
|
2018-09-20 12:25:44 +00:00
|
|
|
- var startInChunk = start % LZ4.CHUNK_SIZE;
|
|
|
|
- var endInChunk = Math.min(startInChunk + desired, LZ4.CHUNK_SIZE);
|
2018-09-17 19:30:25 +00:00
|
|
|
- buffer.set(currChunk.subarray(startInChunk, endInChunk), offset + written);
|
|
|
|
var currWritten = endInChunk - startInChunk;
|
|
|
|
written += currWritten;
|
|
|
|
}
|
2018-09-21 18:53:13 +00:00
|
|
|
@@ -181,4 +180,3 @@ if (LibraryManager.library['$FS__deps']) {
|
2018-09-17 19:30:25 +00:00
|
|
|
warn('FS does not seem to be in use (no preloaded files etc.), LZ4 will not do anything');
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
-
|