@loaders.gl/tile-converter 4.1.0-alpha.9 → 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/3d-tiles-converter/3d-tiles-converter.d.ts.map +1 -1
- package/dist/3d-tiles-converter/3d-tiles-converter.js +4 -4
- package/dist/3d-tiles-converter/3d-tiles-converter.js.map +1 -1
- package/dist/3d-tiles-converter/helpers/b3dm-converter.d.ts.map +1 -1
- package/dist/3d-tiles-converter/helpers/b3dm-converter.js +8 -0
- package/dist/3d-tiles-converter/helpers/b3dm-converter.js.map +1 -1
- package/dist/3d-tiles-converter/json-templates/tileset.d.ts.map +1 -1
- package/dist/3d-tiles-converter/json-templates/tileset.js +3 -0
- package/dist/3d-tiles-converter/json-templates/tileset.js.map +1 -1
- package/dist/constants.d.ts +1 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +1 -0
- package/dist/constants.js.map +1 -1
- package/dist/converter-cli.js +3 -3
- package/dist/converter-cli.js.map +1 -1
- package/dist/converter.min.cjs +131 -220
- package/dist/deps-installer/deps-installer.js +1 -1
- package/dist/deps-installer/deps-installer.js.map +1 -1
- package/dist/i3s-converter/helpers/progress.js +1 -1
- package/dist/i3s-converter/helpers/progress.js.map +1 -1
- package/dist/i3s-converter/i3s-converter.d.ts +14 -0
- package/dist/i3s-converter/i3s-converter.d.ts.map +1 -1
- package/dist/i3s-converter/i3s-converter.js +76 -25
- package/dist/i3s-converter/i3s-converter.js.map +1 -1
- package/dist/i3s-converter/types.d.ts +7 -0
- package/dist/i3s-converter/types.d.ts.map +1 -1
- package/dist/i3s-converter/types.js +8 -0
- package/dist/i3s-converter/types.js.map +1 -1
- package/dist/i3s-server/bin/i3s-server.min.cjs +76 -76
- package/dist/index.cjs +376 -104
- package/dist/lib/utils/compress-util.d.ts +0 -37
- package/dist/lib/utils/compress-util.d.ts.map +1 -1
- package/dist/lib/utils/compress-util.js +1 -149
- package/dist/lib/utils/compress-util.js.map +1 -1
- package/dist/lib/utils/conversion-dump.d.ts +81 -0
- package/dist/lib/utils/conversion-dump.d.ts.map +1 -0
- package/dist/lib/utils/conversion-dump.js +131 -0
- package/dist/lib/utils/conversion-dump.js.map +1 -0
- package/dist/lib/utils/statistic-utills.js +1 -1
- package/dist/lib/utils/statistic-utills.js.map +1 -1
- package/dist/lib/utils/write-queue.d.ts +6 -1
- package/dist/lib/utils/write-queue.d.ts.map +1 -1
- package/dist/lib/utils/write-queue.js +15 -3
- package/dist/lib/utils/write-queue.js.map +1 -1
- package/dist/pgm-loader.js +1 -1
- package/dist/pgm-loader.js.map +1 -1
- package/dist/slpk-extractor.min.cjs +31 -31
- package/package.json +16 -16
- package/src/3d-tiles-converter/3d-tiles-converter.ts +5 -4
- package/src/3d-tiles-converter/helpers/b3dm-converter.ts +19 -0
- package/src/3d-tiles-converter/json-templates/tileset.ts +3 -0
- package/src/constants.ts +1 -0
- package/src/converter-cli.ts +3 -3
- package/src/i3s-converter/helpers/progress.ts +1 -1
- package/src/i3s-converter/i3s-converter.ts +192 -57
- package/src/i3s-converter/types.ts +8 -0
- package/src/lib/utils/compress-util.ts +1 -264
- package/src/lib/utils/conversion-dump.ts +203 -0
- package/src/lib/utils/statistic-utills.ts +1 -1
- package/src/lib/utils/write-queue.ts +15 -2
|
@@ -5,41 +5,4 @@
|
|
|
5
5
|
* @return the path to the gzip file
|
|
6
6
|
*/
|
|
7
7
|
export declare function compressFileWithGzip(pathFile: string): Promise<string>;
|
|
8
|
-
/**
|
|
9
|
-
* Compress files from map into slpk file
|
|
10
|
-
*
|
|
11
|
-
* @param fileMap - map with file paths (key: output path, value: input path)
|
|
12
|
-
* @param outputFile - output slpk file
|
|
13
|
-
* @param level - compression level
|
|
14
|
-
*/
|
|
15
|
-
export declare function compressFilesWithZip(fileMap: {
|
|
16
|
-
[key: string]: string;
|
|
17
|
-
}, outputFile: string, level?: number): Promise<unknown>;
|
|
18
|
-
/**
|
|
19
|
-
* Compress files using external tool 'zip'/'7z'
|
|
20
|
-
*
|
|
21
|
-
* @param inputFolder - folder to archive - for cwd option
|
|
22
|
-
* @param outputFile - output slpk file
|
|
23
|
-
* @param level - compression level
|
|
24
|
-
* @param inputFiles - input files path to pass to the executable as option
|
|
25
|
-
* @param sevenZipExe - path to 7z.exe executable
|
|
26
|
-
*/
|
|
27
|
-
export declare function compressWithChildProcess(inputFolder: string, outputFile: string, level: number, inputFiles: string, sevenZipExe: string): Promise<void>;
|
|
28
|
-
/**
|
|
29
|
-
* Generate hash file from zip archive
|
|
30
|
-
* https://github.com/Esri/i3s-spec/blob/master/docs/1.7/slpk_hashtable.cmn.md
|
|
31
|
-
*
|
|
32
|
-
* @param inputZipFile
|
|
33
|
-
* @param outputFile
|
|
34
|
-
*/
|
|
35
|
-
export declare function generateHash128FromZip(inputZipFile: string, outputFile: string): Promise<unknown>;
|
|
36
|
-
/**
|
|
37
|
-
* Add file to zip archive
|
|
38
|
-
*
|
|
39
|
-
* @param inputFile
|
|
40
|
-
* @param fileName
|
|
41
|
-
* @param zipFile
|
|
42
|
-
* @param sevenZipExe
|
|
43
|
-
*/
|
|
44
|
-
export declare function addFileToZip(inputFolder: string, fileName: string, zipFile: string, sevenZipExe: string): Promise<void>;
|
|
45
8
|
//# sourceMappingURL=compress-util.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compress-util.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/compress-util.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"compress-util.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/compress-util.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAiBtE"}
|
|
@@ -1,13 +1,5 @@
|
|
|
1
1
|
import { createGzip } from 'zlib';
|
|
2
|
-
import {
|
|
3
|
-
import { promises as fs, createReadStream, createWriteStream } from 'fs';
|
|
4
|
-
import archiver from 'archiver';
|
|
5
|
-
import { removeFile } from "./file-utils.js";
|
|
6
|
-
import { ChildProcessProxy } from '@loaders.gl/worker-utils';
|
|
7
|
-
import JSZip from 'jszip';
|
|
8
|
-
import { MD5Hash } from '@loaders.gl/crypto';
|
|
9
|
-
import crypt from 'crypt';
|
|
10
|
-
import { getAbsoluteFilePath } from "./file-utils.js";
|
|
2
|
+
import { createReadStream, createWriteStream } from 'fs';
|
|
11
3
|
export function compressFileWithGzip(pathFile) {
|
|
12
4
|
const compressedPathFile = `${pathFile}.gz`;
|
|
13
5
|
const gzip = createGzip();
|
|
@@ -25,144 +17,4 @@ export function compressFileWithGzip(pathFile) {
|
|
|
25
17
|
input.pipe(gzip).pipe(output);
|
|
26
18
|
});
|
|
27
19
|
}
|
|
28
|
-
export async function compressFilesWithZip(fileMap, outputFile) {
|
|
29
|
-
let level = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
30
|
-
try {
|
|
31
|
-
await removeFile(outputFile);
|
|
32
|
-
} catch (e) {}
|
|
33
|
-
const output = createWriteStream(outputFile);
|
|
34
|
-
const archive = archiver('zip', {
|
|
35
|
-
zlib: {
|
|
36
|
-
level
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
return new Promise(async (resolve, reject) => {
|
|
40
|
-
output.on('close', function () {
|
|
41
|
-
console.log(`${outputFile} saved.`);
|
|
42
|
-
console.log(`${archive.pointer()} total bytes`);
|
|
43
|
-
resolve(null);
|
|
44
|
-
});
|
|
45
|
-
output.on('end', function () {
|
|
46
|
-
console.log('Data has been drained');
|
|
47
|
-
resolve(null);
|
|
48
|
-
});
|
|
49
|
-
archive.on('warning', function (err) {
|
|
50
|
-
console.log(err);
|
|
51
|
-
reject(err);
|
|
52
|
-
});
|
|
53
|
-
archive.on('error', function (err) {
|
|
54
|
-
reject(err);
|
|
55
|
-
});
|
|
56
|
-
archive.pipe(output);
|
|
57
|
-
for (const subFileName in fileMap) {
|
|
58
|
-
const subFileData = fileMap[subFileName];
|
|
59
|
-
await appendFileToArchive(archive, subFileName, subFileData);
|
|
60
|
-
}
|
|
61
|
-
archive.finalize();
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
export async function compressWithChildProcess(inputFolder, outputFile, level, inputFiles, sevenZipExe) {
|
|
65
|
-
if (process.platform === 'win32') {
|
|
66
|
-
await compressWithChildProcessWindows(inputFolder, outputFile, level, inputFiles, sevenZipExe);
|
|
67
|
-
} else {
|
|
68
|
-
await compressWithChildProcessUnix(inputFolder, outputFile, level, inputFiles);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
async function compressWithChildProcessUnix(inputFolder, outputFile) {
|
|
72
|
-
let level = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
73
|
-
let inputFiles = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : '.';
|
|
74
|
-
const fullOutputFile = getAbsoluteFilePath(outputFile);
|
|
75
|
-
const args = [`-${level}`, '-r', fullOutputFile, inputFiles];
|
|
76
|
-
const childProcess = new ChildProcessProxy();
|
|
77
|
-
await childProcess.start({
|
|
78
|
-
command: 'zip',
|
|
79
|
-
arguments: args,
|
|
80
|
-
spawn: {
|
|
81
|
-
cwd: inputFolder
|
|
82
|
-
},
|
|
83
|
-
wait: 0
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
async function compressWithChildProcessWindows(inputFolder, outputFile) {
|
|
87
|
-
let level = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
88
|
-
let inputFiles = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : join('.', '*');
|
|
89
|
-
let sevenZipExe = arguments.length > 4 ? arguments[4] : undefined;
|
|
90
|
-
if (inputFiles[0] === '@') {
|
|
91
|
-
inputFiles = `*${inputFiles.substr(1)}`;
|
|
92
|
-
}
|
|
93
|
-
const fullOutputFile = getAbsoluteFilePath(outputFile);
|
|
94
|
-
const args = ['a', '-tzip', `-mx=${level}`, fullOutputFile, inputFiles];
|
|
95
|
-
const childProcess = new ChildProcessProxy();
|
|
96
|
-
await childProcess.start({
|
|
97
|
-
command: sevenZipExe,
|
|
98
|
-
arguments: args,
|
|
99
|
-
spawn: {
|
|
100
|
-
cwd: `${inputFolder}`
|
|
101
|
-
},
|
|
102
|
-
wait: 0
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
export async function generateHash128FromZip(inputZipFile, outputFile) {
|
|
106
|
-
const input = await fs.readFile(inputZipFile);
|
|
107
|
-
const zip = await JSZip.loadAsync(input);
|
|
108
|
-
const hashTable = [];
|
|
109
|
-
const zipFiles = zip.files;
|
|
110
|
-
for (const relativePath in zipFiles) {
|
|
111
|
-
const zipEntry = zipFiles[relativePath];
|
|
112
|
-
const _data = '_data';
|
|
113
|
-
const content = zipEntry[_data].compressedContent;
|
|
114
|
-
if (zipEntry.dir) continue;
|
|
115
|
-
const hash = await new MD5Hash().hash(Buffer.from(relativePath.toLowerCase()), 'base64');
|
|
116
|
-
hashTable.push({
|
|
117
|
-
key: atob(hash),
|
|
118
|
-
value: content.byteOffset
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
hashTable.sort((prev, next) => {
|
|
122
|
-
if (prev.key === next.key) {
|
|
123
|
-
return prev.value < next.value ? -1 : 1;
|
|
124
|
-
}
|
|
125
|
-
return prev.key < next.key ? -1 : 1;
|
|
126
|
-
});
|
|
127
|
-
const output = createWriteStream(outputFile);
|
|
128
|
-
return new Promise((resolve, reject) => {
|
|
129
|
-
output.on('close', function () {
|
|
130
|
-
console.log(`${outputFile} generated and saved`);
|
|
131
|
-
resolve(null);
|
|
132
|
-
});
|
|
133
|
-
output.on('error', function (err) {
|
|
134
|
-
console.log(err);
|
|
135
|
-
reject(err);
|
|
136
|
-
});
|
|
137
|
-
for (const key in hashTable) {
|
|
138
|
-
const item = hashTable[key];
|
|
139
|
-
const value = longToByteArray(item.value);
|
|
140
|
-
output.write(Buffer.from(crypt.hexToBytes(item.key).concat(value)));
|
|
141
|
-
}
|
|
142
|
-
output.close();
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
function longToByteArray(long) {
|
|
146
|
-
const buffer = new ArrayBuffer(8);
|
|
147
|
-
const longNum = new Float64Array(buffer);
|
|
148
|
-
longNum[0] = parseInt(long);
|
|
149
|
-
return Array.from(new Uint8Array(buffer)).reverse();
|
|
150
|
-
}
|
|
151
|
-
export async function addFileToZip(inputFolder, fileName, zipFile, sevenZipExe) {
|
|
152
|
-
await compressWithChildProcess(inputFolder, zipFile, 0, fileName, sevenZipExe);
|
|
153
|
-
console.log(`${fileName} added to ${zipFile}.`);
|
|
154
|
-
}
|
|
155
|
-
function appendFileToArchive(archive, subFileName, subFileData) {
|
|
156
|
-
return new Promise(resolve => {
|
|
157
|
-
const fileStream = createReadStream(subFileData);
|
|
158
|
-
console.log(`Compression start: ${subFileName}`);
|
|
159
|
-
fileStream.on('close', () => {
|
|
160
|
-
console.log(`Compression finish: ${subFileName}`);
|
|
161
|
-
resolve(null);
|
|
162
|
-
});
|
|
163
|
-
archive.append(fileStream, {
|
|
164
|
-
name: subFileName
|
|
165
|
-
});
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
20
|
//# sourceMappingURL=compress-util.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compress-util.js","names":["createGzip","join","promises","fs","createReadStream","createWriteStream","archiver","removeFile","ChildProcessProxy","JSZip","MD5Hash","crypt","getAbsoluteFilePath","compressFileWithGzip","pathFile","compressedPathFile","gzip","input","output","Promise","resolve","reject","on","console","log","error","pipe","compressFilesWithZip","fileMap","outputFile","level","arguments","length","undefined","e","archive","zlib","pointer","err","subFileName","subFileData","appendFileToArchive","finalize","compressWithChildProcess","inputFolder","inputFiles","sevenZipExe","process","platform","compressWithChildProcessWindows","compressWithChildProcessUnix","fullOutputFile","args","childProcess","start","command","spawn","cwd","wait","substr","generateHash128FromZip","inputZipFile","readFile","zip","loadAsync","hashTable","zipFiles","files","relativePath","zipEntry","_data","content","compressedContent","dir","hash","Buffer","from","toLowerCase","push","key","atob","value","byteOffset","sort","prev","next","item","longToByteArray","write","hexToBytes","concat","close","long","buffer","ArrayBuffer","longNum","Float64Array","parseInt","Array","Uint8Array","reverse","addFileToZip","fileName","zipFile","fileStream","append","name"],"sources":["../../../src/lib/utils/compress-util.ts"],"sourcesContent":["import {createGzip} from 'zlib';\nimport {join} from 'path';\nimport {promises as fs, createReadStream, createWriteStream} from 'fs';\nimport archiver from 'archiver';\nimport {removeFile} from './file-utils';\nimport {ChildProcessProxy} from '@loaders.gl/worker-utils';\nimport JSZip from 'jszip';\nimport {MD5Hash} from '@loaders.gl/crypto';\nimport crypt from 'crypt';\nimport {getAbsoluteFilePath} from './file-utils';\n\n/**\n * Compress file to gzip file\n *\n * @param pathFile - the path to the file\n * @return the path to the gzip file\n */\nexport function compressFileWithGzip(pathFile: string): Promise<string> {\n const compressedPathFile = `${pathFile}.gz`;\n const gzip = createGzip();\n const input = createReadStream(pathFile);\n const output = createWriteStream(compressedPathFile);\n\n return new Promise((resolve, reject) => {\n input.on('end', () => {\n console.log(`${compressedPathFile} compressed and saved.`); // eslint-disable-line no-undef,no-console\n resolve(compressedPathFile);\n });\n input.on('error', (error) => {\n console.log(`${compressedPathFile}: compression error!`); // eslint-disable-line no-undef,no-console\n reject(error);\n });\n input.pipe(gzip).pipe(output);\n });\n}\n\n/**\n * Compress files from map into slpk file\n *\n * @param fileMap - map with file paths (key: output path, value: input path)\n * @param outputFile - output slpk file\n * @param level - compression level\n */\nexport async function compressFilesWithZip(\n fileMap: {[key: string]: string},\n outputFile: string,\n level: number = 0\n) {\n // Before creating a new file, we need to delete the old file\n try {\n await removeFile(outputFile);\n } catch (e) {\n // Do nothing if old file doesn't exist\n }\n\n const output = createWriteStream(outputFile);\n const archive = archiver('zip', {\n zlib: {level} // Sets the compression level.\n });\n\n return new Promise(async (resolve, reject) => {\n // listen for all archive data to be writte\n // 'close' event is fired only when a file descriptor is involved\n output.on('close', function () {\n console.log(`${outputFile} saved.`); // eslint-disable-line no-undef,no-console\n console.log(`${archive.pointer()} total bytes`); // eslint-disable-line no-undef,no-console\n resolve(null);\n });\n\n // This event is fired when the data source is drained no matter what was the data source.\n // It is not part of this library but rather from the NodeJS Stream API.\n // @see: https://nodejs.org/api/stream.html#stream_event_end\n output.on('end', function () {\n console.log('Data has been drained'); // eslint-disable-line no-undef,no-console\n resolve(null);\n });\n\n // good practice to catch warnings (ie stat failures and other non-blocking errors)\n archive.on('warning', function (err) {\n console.log(err); // eslint-disable-line no-undef,no-console\n reject(err);\n });\n\n // good practice to catch this error explicitly\n archive.on('error', function (err) {\n reject(err);\n });\n\n // pipe archive data to the file\n archive.pipe(output);\n\n for (const subFileName in fileMap) {\n const subFileData = fileMap[subFileName];\n await appendFileToArchive(archive, subFileName, subFileData);\n }\n\n // finalize the archive (ie we are done appending files but streams have to finish yet)\n archive.finalize();\n });\n}\n\n/**\n * Compress files using external tool 'zip'/'7z'\n *\n * @param inputFolder - folder to archive - for cwd option\n * @param outputFile - output slpk file\n * @param level - compression level\n * @param inputFiles - input files path to pass to the executable as option\n * @param sevenZipExe - path to 7z.exe executable\n */\nexport async function compressWithChildProcess(\n inputFolder: string,\n outputFile: string,\n level: number,\n inputFiles: string,\n sevenZipExe: string\n) {\n // eslint-disable-next-line no-undef\n if (process.platform === 'win32') {\n await compressWithChildProcessWindows(inputFolder, outputFile, level, inputFiles, sevenZipExe);\n } else {\n await compressWithChildProcessUnix(inputFolder, outputFile, level, inputFiles);\n }\n}\n\n/**\n * Compress files using external linux tool 'zip'\n *\n * @param inputFolder - folder to archive - for cwd option\n * @param outputFile - output slpk file\n * @param level - compression level\n * @param inputFiles - input files path to pass to the executable as option\n */\nasync function compressWithChildProcessUnix(\n inputFolder: string,\n outputFile: string,\n level: number = 0,\n inputFiles: string = '.'\n) {\n const fullOutputFile = getAbsoluteFilePath(outputFile);\n const args = [`-${level}`, '-r', fullOutputFile, inputFiles];\n const childProcess = new ChildProcessProxy();\n await childProcess.start({\n command: 'zip',\n arguments: args,\n spawn: {\n cwd: inputFolder\n },\n wait: 0\n });\n}\n\n/**\n * Compress files using windows external tool '7z'\n *\n * @param inputFolder - folder to archive - for cwd option\n * @param outputFile - output slpk file\n * @param level - compression level\n * @param inputFiles - input files path to pass to the executable as option\n * @param sevenZipExe - path to 7z.exe executable\n */\nasync function compressWithChildProcessWindows(\n inputFolder: string,\n outputFile: string,\n level: number = 0,\n inputFiles: string = join('.', '*'),\n sevenZipExe: string\n) {\n // Workaround for @listfile issue. In 7z.exe @-leading files are handled as listfiles\n // https://sevenzip.osdn.jp/chm/cmdline/syntax.htm\n if (inputFiles[0] === '@') {\n inputFiles = `*${inputFiles.substr(1)}`;\n }\n\n const fullOutputFile = getAbsoluteFilePath(outputFile);\n const args = ['a', '-tzip', `-mx=${level}`, fullOutputFile, inputFiles];\n const childProcess = new ChildProcessProxy();\n await childProcess.start({\n command: sevenZipExe,\n arguments: args,\n spawn: {\n cwd: `${inputFolder}`\n },\n wait: 0\n });\n}\n\n/**\n * Generate hash file from zip archive\n * https://github.com/Esri/i3s-spec/blob/master/docs/1.7/slpk_hashtable.cmn.md\n *\n * @param inputZipFile\n * @param outputFile\n */\nexport async function generateHash128FromZip(inputZipFile: string, outputFile: string) {\n const input = await fs.readFile(inputZipFile);\n const zip = await JSZip.loadAsync(input);\n const hashTable: {key: string; value: string}[] = [];\n const zipFiles = zip.files;\n for (const relativePath in zipFiles) {\n const zipEntry = zipFiles[relativePath];\n // Had to use a workaround because the correct string is getting the wrong data\n // const content = await zipEntry.async('nodebuffer');\n // _data isn't described in the interface, so lint thought it was wrong\n const _data = '_data';\n const content = zipEntry[_data].compressedContent;\n if (zipEntry.dir) continue; // eslint-disable-line no-continue\n // eslint-disable-next-line no-undef\n const hash = await new MD5Hash().hash(Buffer.from(relativePath.toLowerCase()), 'base64');\n // eslint-disable-next-line no-undef\n hashTable.push({key: atob(hash), value: content.byteOffset});\n }\n\n hashTable.sort((prev, next) => {\n if (prev.key === next.key) {\n return prev.value < next.value ? -1 : 1;\n }\n return prev.key < next.key ? -1 : 1;\n });\n\n const output = createWriteStream(outputFile);\n return new Promise((resolve, reject) => {\n output.on('close', function () {\n console.log(`${outputFile} generated and saved`); // eslint-disable-line\n resolve(null);\n });\n output.on('error', function (err) {\n console.log(err); // eslint-disable-line\n reject(err);\n });\n for (const key in hashTable) {\n const item = hashTable[key];\n const value = longToByteArray(item.value);\n // TODO: perhaps you need to wait for the 'drain' event if the write returns 'false'\n // eslint-disable-next-line no-undef\n output.write(Buffer.from(crypt.hexToBytes(item.key).concat(value)));\n }\n output.close();\n });\n}\n\n/**\n * Encode 64 bit value to byte array\n *\n * @param long - stringified number\n * @returns\n */\nfunction longToByteArray(long: string): number[] {\n const buffer = new ArrayBuffer(8); // JS numbers are 8 bytes long, or 64 bits\n const longNum = new Float64Array(buffer); // so equivalent to Float64\n longNum[0] = parseInt(long);\n return Array.from(new Uint8Array(buffer)).reverse(); // reverse to get little endian\n}\n\n/**\n * Add file to zip archive\n *\n * @param inputFile\n * @param fileName\n * @param zipFile\n * @param sevenZipExe\n */\nexport async function addFileToZip(\n inputFolder: string,\n fileName: string,\n zipFile: string,\n sevenZipExe: string\n) {\n await compressWithChildProcess(inputFolder, zipFile, 0, fileName, sevenZipExe);\n console.log(`${fileName} added to ${zipFile}.`); // eslint-disable-line\n}\n\n/**\n *\n * @param archive zip archive instance\n * @param subFileName file path inside archive\n * @param subFileData source file path\n * @returns\n */\nfunction appendFileToArchive(archive: any, subFileName: string, subFileData: string) {\n return new Promise((resolve) => {\n const fileStream = createReadStream(subFileData);\n console.log(`Compression start: ${subFileName}`); // eslint-disable-line no-undef,no-console\n fileStream.on('close', () => {\n console.log(`Compression finish: ${subFileName}`); // eslint-disable-line no-undef,no-console\n resolve(null);\n });\n archive.append(fileStream, {name: subFileName});\n });\n}\n"],"mappings":"AAAA,SAAQA,UAAU,QAAO,MAAM;AAC/B,SAAQC,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;EACjD,CAAC,CAAC;AACJ"}
|
|
1
|
+
{"version":3,"file":"compress-util.js","names":["createGzip","createReadStream","createWriteStream","compressFileWithGzip","pathFile","compressedPathFile","gzip","input","output","Promise","resolve","reject","on","console","log","error","pipe"],"sources":["../../../src/lib/utils/compress-util.ts"],"sourcesContent":["import {createGzip} from 'zlib';\nimport {createReadStream, createWriteStream} from 'fs';\n\n/**\n * Compress file to gzip file\n *\n * @param pathFile - the path to the file\n * @return the path to the gzip file\n */\nexport function compressFileWithGzip(pathFile: string): Promise<string> {\n const compressedPathFile = `${pathFile}.gz`;\n const gzip = createGzip();\n const input = createReadStream(pathFile);\n const output = createWriteStream(compressedPathFile);\n\n return new Promise((resolve, reject) => {\n input.on('end', () => {\n console.log(`${compressedPathFile} compressed and saved.`); // eslint-disable-line no-undef,no-console\n resolve(compressedPathFile);\n });\n input.on('error', (error) => {\n console.log(`${compressedPathFile}: compression error!`); // eslint-disable-line no-undef,no-console\n reject(error);\n });\n input.pipe(gzip).pipe(output);\n });\n}\n"],"mappings":"AAAA,SAAQA,UAAU,QAAO,MAAM;AAC/B,SAAQC,gBAAgB,EAAEC,iBAAiB,QAAO,IAAI;AAQtD,OAAO,SAASC,oBAAoBA,CAACC,QAAgB,EAAmB;EACtE,MAAMC,kBAAkB,GAAI,GAAED,QAAS,KAAI;EAC3C,MAAME,IAAI,GAAGN,UAAU,CAAC,CAAC;EACzB,MAAMO,KAAK,GAAGN,gBAAgB,CAACG,QAAQ,CAAC;EACxC,MAAMI,MAAM,GAAGN,iBAAiB,CAACG,kBAAkB,CAAC;EAEpD,OAAO,IAAII,OAAO,CAAC,CAACC,OAAO,EAAEC,MAAM,KAAK;IACtCJ,KAAK,CAACK,EAAE,CAAC,KAAK,EAAE,MAAM;MACpBC,OAAO,CAACC,GAAG,CAAE,GAAET,kBAAmB,wBAAuB,CAAC;MAC1DK,OAAO,CAACL,kBAAkB,CAAC;IAC7B,CAAC,CAAC;IACFE,KAAK,CAACK,EAAE,CAAC,OAAO,EAAGG,KAAK,IAAK;MAC3BF,OAAO,CAACC,GAAG,CAAE,GAAET,kBAAmB,sBAAqB,CAAC;MACxDM,MAAM,CAACI,KAAK,CAAC;IACf,CAAC,CAAC;IACFR,KAAK,CAACS,IAAI,CAACV,IAAI,CAAC,CAACU,IAAI,CAACR,MAAM,CAAC;EAC/B,CAAC,CAAC;AACJ"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
export type ConversionDumpOptions = {
|
|
2
|
+
inputUrl: string;
|
|
3
|
+
outputPath: string;
|
|
4
|
+
tilesetName: string;
|
|
5
|
+
maxDepth: number;
|
|
6
|
+
slpk: boolean;
|
|
7
|
+
egmFilePath: string;
|
|
8
|
+
token: string;
|
|
9
|
+
draco: boolean;
|
|
10
|
+
mergeMaterials: boolean;
|
|
11
|
+
generateTextures: boolean;
|
|
12
|
+
generateBoundingVolumes: boolean;
|
|
13
|
+
metadataClass: string;
|
|
14
|
+
analyze: boolean;
|
|
15
|
+
};
|
|
16
|
+
type NodeDoneStatus = {
|
|
17
|
+
nodeId: number;
|
|
18
|
+
done: boolean;
|
|
19
|
+
progress: Record<string, boolean>;
|
|
20
|
+
};
|
|
21
|
+
type TilesConverted = {
|
|
22
|
+
nodes: NodeDoneStatus[];
|
|
23
|
+
};
|
|
24
|
+
export declare class ConversionDump {
|
|
25
|
+
/** Conversion options */
|
|
26
|
+
private options?;
|
|
27
|
+
/** Tiles conversion progress status map */
|
|
28
|
+
tilesConverted: Record<string, TilesConverted>;
|
|
29
|
+
constructor();
|
|
30
|
+
/**
|
|
31
|
+
* Create a dump file with convertion options
|
|
32
|
+
* @param options - converter options
|
|
33
|
+
*/
|
|
34
|
+
createDumpFile(options: ConversionDumpOptions): Promise<void>;
|
|
35
|
+
/**
|
|
36
|
+
* Update conversion status in the dump file
|
|
37
|
+
*/
|
|
38
|
+
private updateDumpFile;
|
|
39
|
+
/**
|
|
40
|
+
* Delete a dump file
|
|
41
|
+
*/
|
|
42
|
+
deleteDumpFile(): Promise<void>;
|
|
43
|
+
/**
|
|
44
|
+
* Get record from the tilesConverted Map
|
|
45
|
+
* @param fileName - source filename
|
|
46
|
+
* @returns existing object from the tilesConverted Map
|
|
47
|
+
*/
|
|
48
|
+
private getRecord;
|
|
49
|
+
/**
|
|
50
|
+
* Set a record for the dump file
|
|
51
|
+
* @param fileName - key - source filename
|
|
52
|
+
* @param object - value
|
|
53
|
+
*/
|
|
54
|
+
private setRecord;
|
|
55
|
+
/**
|
|
56
|
+
* Add a node into the dump file for the source file record
|
|
57
|
+
* @param fileName - source filename
|
|
58
|
+
* @param nodeId - nodeId of the node
|
|
59
|
+
*/
|
|
60
|
+
addNode(filename: string, nodeId: number): Promise<void>;
|
|
61
|
+
/**
|
|
62
|
+
* Update done status object for the writing resources
|
|
63
|
+
* @param fileName - key - source filename
|
|
64
|
+
* @param nodeId - nodeId for the source filename
|
|
65
|
+
* @param resourceType - resource type to update status
|
|
66
|
+
* @param value - value
|
|
67
|
+
*/
|
|
68
|
+
updateDoneStatus(filename: string, nodeId: number, resourceType: string, value: boolean): void;
|
|
69
|
+
/**
|
|
70
|
+
* Update dump file according to writing results
|
|
71
|
+
* @param changedRecords - array of parameters ids for the written resources
|
|
72
|
+
* @param writeResults - array of writing resource files results
|
|
73
|
+
*/
|
|
74
|
+
updateConvertedTilesDump(changedRecords: {
|
|
75
|
+
outputId?: number;
|
|
76
|
+
sourceId?: string;
|
|
77
|
+
resourceType?: string;
|
|
78
|
+
}[], writeResults: PromiseSettledResult<string | null>[]): Promise<void>;
|
|
79
|
+
}
|
|
80
|
+
export {};
|
|
81
|
+
//# sourceMappingURL=conversion-dump.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"conversion-dump.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/conversion-dump.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,qBAAqB,GAAG;IAClC,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,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AC,QAAQ,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;QAAC,YAAY,CAAC,EAAE,MAAM,CAAA;KAAC,EAAE,EAC/E,YAAY,EAAE,oBAAoB,CAAC,MAAM,GAAG,IAAI,CAAC,EAAE;CA0BtD"}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { DUMP_FILE_SUFFIX } from "../../constants.js";
|
|
2
|
+
import { removeFile, writeFile } from "./file-utils.js";
|
|
3
|
+
import { join } from 'path';
|
|
4
|
+
export class ConversionDump {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.options = void 0;
|
|
7
|
+
this.tilesConverted = void 0;
|
|
8
|
+
this.tilesConverted = {};
|
|
9
|
+
}
|
|
10
|
+
async createDumpFile(options) {
|
|
11
|
+
const {
|
|
12
|
+
tilesetName,
|
|
13
|
+
slpk,
|
|
14
|
+
egmFilePath,
|
|
15
|
+
inputUrl,
|
|
16
|
+
outputPath,
|
|
17
|
+
draco = true,
|
|
18
|
+
maxDepth,
|
|
19
|
+
token,
|
|
20
|
+
generateTextures,
|
|
21
|
+
generateBoundingVolumes,
|
|
22
|
+
mergeMaterials = true,
|
|
23
|
+
metadataClass,
|
|
24
|
+
analyze = false
|
|
25
|
+
} = options;
|
|
26
|
+
this.options = {
|
|
27
|
+
tilesetName,
|
|
28
|
+
slpk,
|
|
29
|
+
egmFilePath,
|
|
30
|
+
inputUrl,
|
|
31
|
+
outputPath,
|
|
32
|
+
draco,
|
|
33
|
+
maxDepth,
|
|
34
|
+
token,
|
|
35
|
+
generateTextures,
|
|
36
|
+
generateBoundingVolumes,
|
|
37
|
+
mergeMaterials,
|
|
38
|
+
metadataClass,
|
|
39
|
+
analyze
|
|
40
|
+
};
|
|
41
|
+
try {
|
|
42
|
+
await writeFile(options.outputPath, JSON.stringify({
|
|
43
|
+
options: this.options
|
|
44
|
+
}), `${options.tilesetName}${DUMP_FILE_SUFFIX}`);
|
|
45
|
+
} catch (error) {
|
|
46
|
+
console.log("Can't create dump file", error);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
async updateDumpFile() {
|
|
50
|
+
var _this$options;
|
|
51
|
+
if ((_this$options = this.options) !== null && _this$options !== void 0 && _this$options.outputPath && this.options.tilesetName) {
|
|
52
|
+
try {
|
|
53
|
+
await writeFile(this.options.outputPath, JSON.stringify({
|
|
54
|
+
options: this.options,
|
|
55
|
+
tilesConverted: this.tilesConverted
|
|
56
|
+
}), `${this.options.tilesetName}${DUMP_FILE_SUFFIX}`);
|
|
57
|
+
} catch (error) {
|
|
58
|
+
console.log("Can't update dump file", error);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
async deleteDumpFile() {
|
|
63
|
+
var _this$options2;
|
|
64
|
+
if ((_this$options2 = this.options) !== null && _this$options2 !== void 0 && _this$options2.outputPath && this.options.tilesetName) {
|
|
65
|
+
await removeFile(join(this.options.outputPath, `${this.options.tilesetName}${DUMP_FILE_SUFFIX}`));
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
getRecord(fileName) {
|
|
69
|
+
return this.tilesConverted[fileName];
|
|
70
|
+
}
|
|
71
|
+
setRecord(fileName, object) {
|
|
72
|
+
this.tilesConverted[fileName] = object;
|
|
73
|
+
}
|
|
74
|
+
async addNode(filename, nodeId) {
|
|
75
|
+
const {
|
|
76
|
+
nodes
|
|
77
|
+
} = this.getRecord(filename) || {
|
|
78
|
+
nodes: []
|
|
79
|
+
};
|
|
80
|
+
nodes.push({
|
|
81
|
+
nodeId,
|
|
82
|
+
done: false,
|
|
83
|
+
progress: {}
|
|
84
|
+
});
|
|
85
|
+
if (nodes.length === 1) {
|
|
86
|
+
this.setRecord(filename, {
|
|
87
|
+
nodes
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
await this.updateDumpFile();
|
|
91
|
+
}
|
|
92
|
+
updateDoneStatus(filename, nodeId, resourceType, value) {
|
|
93
|
+
var _this$tilesConverted$;
|
|
94
|
+
const nodeDump = (_this$tilesConverted$ = this.tilesConverted[filename]) === null || _this$tilesConverted$ === void 0 ? void 0 : _this$tilesConverted$.nodes.find(element => element.nodeId === nodeId);
|
|
95
|
+
if (nodeDump) {
|
|
96
|
+
nodeDump.progress[resourceType] = value;
|
|
97
|
+
if (!value) {
|
|
98
|
+
nodeDump.done = false;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
async updateConvertedTilesDump(changedRecords, writeResults) {
|
|
103
|
+
for (let i = 0; i < changedRecords.length; i++) {
|
|
104
|
+
if (changedRecords[i] && 'value' in writeResults[i]) {
|
|
105
|
+
const {
|
|
106
|
+
sourceId,
|
|
107
|
+
resourceType,
|
|
108
|
+
outputId
|
|
109
|
+
} = changedRecords[i];
|
|
110
|
+
if (!sourceId || !resourceType || !outputId) continue;
|
|
111
|
+
for (const node of this.tilesConverted[sourceId].nodes) {
|
|
112
|
+
if (node.nodeId === outputId) {
|
|
113
|
+
node.progress[resourceType] = true;
|
|
114
|
+
let done = false;
|
|
115
|
+
for (const key in node.progress) {
|
|
116
|
+
done = node.progress[key];
|
|
117
|
+
if (!done) break;
|
|
118
|
+
}
|
|
119
|
+
node.done = done;
|
|
120
|
+
if (node.done) {
|
|
121
|
+
node.progress = {};
|
|
122
|
+
}
|
|
123
|
+
break;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
await this.updateDumpFile();
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
//# sourceMappingURL=conversion-dump.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"conversion-dump.js","names":["DUMP_FILE_SUFFIX","removeFile","writeFile","join","ConversionDump","constructor","options","tilesConverted","createDumpFile","tilesetName","slpk","egmFilePath","inputUrl","outputPath","draco","maxDepth","token","generateTextures","generateBoundingVolumes","mergeMaterials","metadataClass","analyze","JSON","stringify","error","console","log","updateDumpFile","_this$options","deleteDumpFile","_this$options2","getRecord","fileName","setRecord","object","addNode","filename","nodeId","nodes","push","done","progress","length","updateDoneStatus","resourceType","value","_this$tilesConverted$","nodeDump","find","element","updateConvertedTilesDump","changedRecords","writeResults","i","sourceId","outputId","node","key"],"sources":["../../../src/lib/utils/conversion-dump.ts"],"sourcesContent":["import {DUMP_FILE_SUFFIX} from '../../constants';\nimport {removeFile, writeFile} from './file-utils';\nimport {join} from 'path';\n\nexport type ConversionDumpOptions = {\n inputUrl: string;\n outputPath: string;\n tilesetName: string;\n maxDepth: number;\n slpk: boolean;\n egmFilePath: string;\n token: string;\n draco: boolean;\n mergeMaterials: boolean;\n generateTextures: boolean;\n generateBoundingVolumes: boolean;\n metadataClass: string;\n analyze: boolean;\n};\n\ntype NodeDoneStatus = {\n nodeId: number;\n done: boolean;\n progress: Record<string, boolean>;\n};\n\ntype TilesConverted = {\n nodes: NodeDoneStatus[];\n};\n\nexport class ConversionDump {\n /** Conversion options */\n private options?: ConversionDumpOptions;\n /** Tiles conversion progress status map */\n tilesConverted: Record<string, TilesConverted>;\n\n constructor() {\n this.tilesConverted = {};\n }\n\n /**\n * Create a dump file with convertion options\n * @param options - converter options\n */\n async createDumpFile(options: ConversionDumpOptions): Promise<void> {\n const {\n tilesetName,\n slpk,\n egmFilePath,\n inputUrl,\n outputPath,\n draco = true,\n maxDepth,\n token,\n generateTextures,\n generateBoundingVolumes,\n mergeMaterials = true,\n metadataClass,\n analyze = false\n } = options;\n this.options = {\n tilesetName,\n slpk,\n egmFilePath,\n inputUrl,\n outputPath,\n draco,\n maxDepth,\n token,\n generateTextures,\n generateBoundingVolumes,\n mergeMaterials,\n metadataClass,\n analyze\n };\n\n try {\n await writeFile(\n options.outputPath,\n JSON.stringify({options: this.options}),\n `${options.tilesetName}${DUMP_FILE_SUFFIX}`\n );\n } catch (error) {\n console.log(\"Can't create dump file\", error);\n }\n }\n\n /**\n * Update conversion status in the dump file\n */\n private async updateDumpFile(): Promise<void> {\n if (this.options?.outputPath && this.options.tilesetName) {\n try {\n await writeFile(\n this.options.outputPath,\n JSON.stringify({\n options: this.options,\n tilesConverted: this.tilesConverted\n }),\n `${this.options.tilesetName}${DUMP_FILE_SUFFIX}`\n );\n } catch (error) {\n console.log(\"Can't update dump file\", error);\n }\n }\n }\n\n /**\n * Delete a dump file\n */\n async deleteDumpFile(): Promise<void> {\n if (this.options?.outputPath && this.options.tilesetName) {\n await removeFile(\n join(this.options.outputPath, `${this.options.tilesetName}${DUMP_FILE_SUFFIX}`)\n );\n }\n }\n\n /**\n * Get record from the tilesConverted Map\n * @param fileName - source filename\n * @returns existing object from the tilesConverted Map\n */\n private getRecord(fileName: string) {\n return this.tilesConverted[fileName];\n }\n\n /**\n * Set a record for the dump file\n * @param fileName - key - source filename\n * @param object - value\n */\n private setRecord(fileName: string, object: any) {\n this.tilesConverted[fileName] = object;\n }\n\n /**\n * Add a node into the dump file for the source file record\n * @param fileName - source filename\n * @param nodeId - nodeId of the node\n */\n async addNode(filename: string, nodeId: number) {\n const {nodes} = this.getRecord(filename) || {nodes: []};\n nodes.push({nodeId, done: false, progress: {}});\n if (nodes.length === 1) {\n this.setRecord(filename, {nodes});\n }\n await this.updateDumpFile();\n }\n\n /**\n * Update done status object for the writing resources\n * @param fileName - key - source filename\n * @param nodeId - nodeId for the source filename\n * @param resourceType - resource type to update status\n * @param value - value\n */\n updateDoneStatus(filename: string, nodeId: number, resourceType: string, value: boolean) {\n const nodeDump = this.tilesConverted[filename]?.nodes.find(\n (element) => element.nodeId === nodeId\n );\n if (nodeDump) {\n nodeDump.progress[resourceType] = value;\n if (!value) {\n nodeDump.done = false;\n }\n }\n }\n\n /**\n * Update dump file according to writing results\n * @param changedRecords - array of parameters ids for the written resources\n * @param writeResults - array of writing resource files results\n */\n async updateConvertedTilesDump(\n changedRecords: {outputId?: number; sourceId?: string; resourceType?: string}[],\n writeResults: PromiseSettledResult<string | null>[]\n ) {\n for (let i = 0; i < changedRecords.length; i++) {\n if (changedRecords[i] && 'value' in writeResults[i]) {\n const {sourceId, resourceType, outputId} = changedRecords[i];\n if (!sourceId || !resourceType || !outputId) continue;\n for (const node of this.tilesConverted[sourceId].nodes) {\n if (node.nodeId === outputId) {\n node.progress[resourceType] = true;\n\n let done = false;\n for (const key in node.progress) {\n done = node.progress[key];\n if (!done) break;\n }\n node.done = done;\n if (node.done) {\n node.progress = {};\n }\n break;\n }\n }\n }\n }\n await this.updateDumpFile();\n }\n}\n"],"mappings":"SAAQA,gBAAgB;AAAA,SAChBC,UAAU,EAAEC,SAAS;AAC7B,SAAQC,IAAI,QAAO,MAAM;AA4BzB,OAAO,MAAMC,cAAc,CAAC;EAM1BC,WAAWA,CAAA,EAAG;IAAA,KAJNC,OAAO;IAAA,KAEfC,cAAc;IAGZ,IAAI,CAACA,cAAc,GAAG,CAAC,CAAC;EAC1B;EAMA,MAAMC,cAAcA,CAACF,OAA8B,EAAiB;IAClE,MAAM;MACJG,WAAW;MACXC,IAAI;MACJC,WAAW;MACXC,QAAQ;MACRC,UAAU;MACVC,KAAK,GAAG,IAAI;MACZC,QAAQ;MACRC,KAAK;MACLC,gBAAgB;MAChBC,uBAAuB;MACvBC,cAAc,GAAG,IAAI;MACrBC,aAAa;MACbC,OAAO,GAAG;IACZ,CAAC,GAAGf,OAAO;IACX,IAAI,CAACA,OAAO,GAAG;MACbG,WAAW;MACXC,IAAI;MACJC,WAAW;MACXC,QAAQ;MACRC,UAAU;MACVC,KAAK;MACLC,QAAQ;MACRC,KAAK;MACLC,gBAAgB;MAChBC,uBAAuB;MACvBC,cAAc;MACdC,aAAa;MACbC;IACF,CAAC;IAED,IAAI;MACF,MAAMnB,SAAS,CACbI,OAAO,CAACO,UAAU,EAClBS,IAAI,CAACC,SAAS,CAAC;QAACjB,OAAO,EAAE,IAAI,CAACA;MAAO,CAAC,CAAC,EACtC,GAAEA,OAAO,CAACG,WAAY,GAAET,gBAAiB,EAC5C,CAAC;IACH,CAAC,CAAC,OAAOwB,KAAK,EAAE;MACd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AE;QAC7C,KAAK,MAAMC,IAAI,IAAI,IAAI,CAACjD,cAAc,CAAC+C,QAAQ,CAAC,CAAChB,KAAK,EAAE;UACtD,IAAIkB,IAAI,CAACnB,MAAM,KAAKkB,QAAQ,EAAE;YAC5BC,IAAI,CAACf,QAAQ,CAACG,YAAY,CAAC,GAAG,IAAI;YAElC,IAAIJ,IAAI,GAAG,KAAK;YAChB,KAAK,MAAMiB,GAAG,IAAID,IAAI,CAACf,QAAQ,EAAE;cAC/BD,IAAI,GAAGgB,IAAI,CAACf,QAAQ,CAACgB,GAAG,CAAC;cACzB,IAAI,CAACjB,IAAI,EAAE;YACb;YACAgB,IAAI,CAAChB,IAAI,GAAGA,IAAI;YAChB,IAAIgB,IAAI,CAAChB,IAAI,EAAE;cACbgB,IAAI,CAACf,QAAQ,GAAG,CAAC,CAAC;YACpB;YACA;UACF;QACF;MACF;IACF;IACA,MAAM,IAAI,CAACd,cAAc,CAAC,CAAC;EAC7B;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"statistic-utills.js","names":["join","promises","fs","getAbsoluteFilePath","timeConverter","time","milliSecondsInSecond","timeInSeconds","Math","floor","milliseconds","timeConverterFromSecondsAndMilliseconds","nanoSecondsInMillisecond","hours","minutes","seconds","result","calculateFilesSize","params","slpk","outputPath","tilesetName","fullOutputPath","slpkPath","stat","size","directoryPath","totalSize","getTotalFilesSize","error","console","log","dirPath","totalFileSize","files","readdir","file","fileStat","isDirectory"],"sources":["../../../src/lib/utils/statistic-utills.ts"],"sourcesContent":["import {join} from 'path';\nimport {promises as fs} from 'fs';\nimport {getAbsoluteFilePath} from './file-utils';\n\n/**\n * Converts time value to string.\n * @param time - high-resolution real time in a [seconds, nanoseconds] tuple Array, or a value on milliseconds.\n * @returns string representation of the time\n */\nexport function timeConverter(time: number | [number, number]): string {\n if (typeof time === 'number') {\n // time - real time in milli-seconds\n const milliSecondsInSecond = 1e3;\n const timeInSeconds = Math.floor(time / milliSecondsInSecond);\n const milliseconds = time - timeInSeconds * milliSecondsInSecond;\n return timeConverterFromSecondsAndMilliseconds(timeInSeconds, milliseconds);\n } else {\n // time - high-resolution real time in a [seconds, nanoseconds] tuple Array\n const nanoSecondsInMillisecond = 1e6;\n const timeInSeconds = time[0];\n const milliseconds = time[1] / nanoSecondsInMillisecond;\n return timeConverterFromSecondsAndMilliseconds(timeInSeconds, milliseconds);\n }\n}\n\nfunction timeConverterFromSecondsAndMilliseconds(timeInSeconds: number, milliseconds: number) {\n const hours = Math.floor(timeInSeconds / 3600);\n timeInSeconds = timeInSeconds - hours * 3600;\n const minutes = Math.floor(timeInSeconds / 60);\n timeInSeconds = timeInSeconds - minutes * 60;\n const seconds = Math.floor(timeInSeconds);\n let result = '';\n\n if (hours) {\n result += `${hours}h `;\n }\n\n if (minutes) {\n result += `${minutes}m `;\n }\n\n if (seconds) {\n result += `${seconds}s`;\n }\n\n if (!result) {\n result += `${milliseconds}ms`;\n }\n\n return result;\n}\n\nexport async function calculateFilesSize(params) {\n const {slpk, outputPath, tilesetName} = params;\n const fullOutputPath = getAbsoluteFilePath(outputPath);\n\n try {\n if (slpk) {\n const slpkPath = join(fullOutputPath, `${tilesetName}.slpk`);\n const stat = await fs.stat(slpkPath);\n return stat.size;\n }\n\n const directoryPath = join(fullOutputPath, tilesetName);\n const totalSize = await getTotalFilesSize(directoryPath);\n return totalSize;\n } catch (error) {\n console.log('Calculate file sizes error: ', error); // eslint-disable-line\n return null;\n }\n}\n\nasync function getTotalFilesSize(dirPath) {\n let totalFileSize = 0;\n\n const files = await fs.readdir(dirPath);\n\n for (const file of files) {\n const fileStat = await fs.stat(join(dirPath, file));\n if (fileStat.isDirectory()) {\n totalFileSize += await getTotalFilesSize(join(dirPath, file));\n } else {\n totalFileSize += fileStat.size;\n }\n }\n return totalFileSize;\n}\n"],"mappings":"AAAA,SAAQA,IAAI,QAAO,MAAM;AACzB,SAAQC,QAAQ,IAAIC,EAAE,QAAO,IAAI;AAAC,SAC1BC,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
|
1
|
+
{"version":3,"file":"statistic-utills.js","names":["join","promises","fs","getAbsoluteFilePath","timeConverter","time","milliSecondsInSecond","timeInSeconds","Math","floor","milliseconds","timeConverterFromSecondsAndMilliseconds","nanoSecondsInMillisecond","hours","minutes","seconds","result","calculateFilesSize","params","slpk","outputPath","tilesetName","fullOutputPath","slpkPath","stat","size","directoryPath","totalSize","getTotalFilesSize","error","console","log","dirPath","totalFileSize","files","readdir","file","fileStat","isDirectory"],"sources":["../../../src/lib/utils/statistic-utills.ts"],"sourcesContent":["import {join} from 'path';\nimport {promises as fs} from 'fs';\nimport {getAbsoluteFilePath} from './file-utils';\n\n/**\n * Converts time value to string.\n * @param time - high-resolution real time in a [seconds, nanoseconds] tuple Array, or a value on milliseconds.\n * @returns string representation of the time\n */\nexport function timeConverter(time: number | [number, number]): string {\n if (typeof time === 'number') {\n // time - real time in milli-seconds\n const milliSecondsInSecond = 1e3;\n const timeInSeconds = Math.floor(time / milliSecondsInSecond);\n const milliseconds = time - timeInSeconds * milliSecondsInSecond;\n return timeConverterFromSecondsAndMilliseconds(timeInSeconds, milliseconds);\n } else {\n // time - high-resolution real time in a [seconds, nanoseconds] tuple Array\n const nanoSecondsInMillisecond = 1e6;\n const timeInSeconds = time[0];\n const milliseconds = time[1] / nanoSecondsInMillisecond;\n return timeConverterFromSecondsAndMilliseconds(timeInSeconds, milliseconds);\n }\n}\n\nfunction timeConverterFromSecondsAndMilliseconds(timeInSeconds: number, milliseconds: number) {\n const hours = Math.floor(timeInSeconds / 3600);\n timeInSeconds = timeInSeconds - hours * 3600;\n const minutes = Math.floor(timeInSeconds / 60);\n timeInSeconds = timeInSeconds - minutes * 60;\n const seconds = Math.floor(timeInSeconds);\n let result = '';\n\n if (hours) {\n result += `${hours}h `;\n }\n\n if (minutes) {\n result += `${minutes}m `;\n }\n\n if (seconds) {\n result += `${seconds}s`;\n }\n\n if (!result) {\n result += `${Math.floor(milliseconds)}ms`;\n }\n\n return result;\n}\n\nexport async function calculateFilesSize(params) {\n const {slpk, outputPath, tilesetName} = params;\n const fullOutputPath = getAbsoluteFilePath(outputPath);\n\n try {\n if (slpk) {\n const slpkPath = join(fullOutputPath, `${tilesetName}.slpk`);\n const stat = await fs.stat(slpkPath);\n return stat.size;\n }\n\n const directoryPath = join(fullOutputPath, tilesetName);\n const totalSize = await getTotalFilesSize(directoryPath);\n return totalSize;\n } catch (error) {\n console.log('Calculate file sizes error: ', error); // eslint-disable-line\n return null;\n }\n}\n\nasync function getTotalFilesSize(dirPath) {\n let totalFileSize = 0;\n\n const files = await fs.readdir(dirPath);\n\n for (const file of files) {\n const fileStat = await fs.stat(join(dirPath, file));\n if (fileStat.isDirectory()) {\n totalFileSize += await getTotalFilesSize(join(dirPath, file));\n } else {\n totalFileSize += fileStat.size;\n }\n }\n return totalFileSize;\n}\n"],"mappings":"AAAA,SAAQA,IAAI,QAAO,MAAM;AACzB,SAAQC,QAAQ,IAAIC,EAAE,QAAO,IAAI;AAAC,SAC1BC,mBAAmB;AAO3B,OAAO,SAASC,aAAaA,CAACC,IAA+B,EAAU;EACrE,IAAI,OAAOA,IAAI,KAAK,QAAQ,EAAE;IAE5B,MAAMC,oBAAoB,GAAG,GAAG;IAChC,MAAMC,aAAa,GAAGC,IAAI,CAACC,KAAK,CAACJ,IAAI,GAAGC,oBAAoB,CAAC;IAC7D,MAAMI,YAAY,GAAGL,IAAI,GAAGE,aAAa,GAAGD,oBAAoB;IAChE,OAAOK,uCAAuC,CAACJ,aAAa,EAAEG,YAAY,CAAC;EAC7E,CAAC,MAAM;IAEL,MAAME,wBAAwB,GAAG,GAAG;IACpC,MAAML,aAAa,GAAGF,IAAI,CAAC,CAAC,CAAC;IAC7B,MAAMK,YAAY,GAAGL,IAAI,CAAC,CAAC,CAAC,GAAGO,wBAAwB;IACvD,OAAOD,uCAAuC,CAACJ,aAAa,EAAEG,YAAY,CAAC;EAC7E;AACF;AAEA,SAASC,uCAAuCA,CAACJ,aAAqB,EAAEG,YAAoB,EAAE;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ClB,CAAC,CAAC,OAAOE,KAAK,EAAE;IACdC,OAAO,CAACC,GAAG,CAAC,8BAA8B,EAAEF,KAAK,CAAC;IAClD,OAAO,IAAI;EACb;AACF;AAEA,eAAeD,iBAAiBA,CAACI,OAAO,EAAE;EACxC,IAAIC,aAAa,GAAG,CAAC;EAErB,MAAMC,KAAK,GAAG,MAAMhC,EAAE,CAACiC,OAAO,CAACH,OAAO,CAAC;EAEvC,KAAK,MAAMI,IAAI,IAAIF,KAAK,EAAE;IACxB,MAAMG,QAAQ,GAAG,MAAMnC,EAAE,CAACsB,IAAI,CAACxB,IAAI,CAACgC,OAAO,EAAEI,IAAI,CAAC,CAAC;IACnD,IAAIC,QAAQ,CAACC,WAAW,CAAC,CAAC,EAAE;MAC1BL,aAAa,IAAI,MAAML,iBAAiB,CAAC5B,IAAI,CAACgC,OAAO,EAAEI,IAAI,CAAC,CAAC;IAC/D,CAAC,MAAM;MACLH,aAAa,IAAII,QAAQ,CAACZ,IAAI;IAChC;EACF;EACA,OAAOQ,aAAa;AACtB"}
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { Queue } from './queue';
|
|
2
|
+
import { ConversionDump } from './conversion-dump';
|
|
2
3
|
export type WriteQueueItem = {
|
|
3
4
|
archiveKey?: string;
|
|
5
|
+
sourceId?: string;
|
|
6
|
+
outputId?: number;
|
|
7
|
+
resourceType?: string;
|
|
4
8
|
/**
|
|
5
9
|
* writePromise() returns a Promise that will be awaited in Promise.allSettled(promises);
|
|
6
10
|
* Arguments for this call are specified in writeQueue.enqueue call like this:
|
|
@@ -21,13 +25,14 @@ export type WriteQueueItem = {
|
|
|
21
25
|
};
|
|
22
26
|
export default class WriteQueue<T extends WriteQueueItem> extends Queue<T> {
|
|
23
27
|
private intervalId?;
|
|
28
|
+
private conversionDump;
|
|
24
29
|
writePromise: Promise<void> | null;
|
|
25
30
|
fileMap: {
|
|
26
31
|
[key: string]: string;
|
|
27
32
|
};
|
|
28
33
|
listeningInterval: number;
|
|
29
34
|
writeConcurrency: number;
|
|
30
|
-
constructor(listeningInterval?: number, writeConcurrency?: number);
|
|
35
|
+
constructor(conversionDump: ConversionDump, listeningInterval?: number, writeConcurrency?: number);
|
|
31
36
|
enqueue(val: T, writeImmediately?: boolean): Promise<void>;
|
|
32
37
|
startListening(): void;
|
|
33
38
|
stopListening(): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"write-queue.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/write-queue.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,EAAC,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"write-queue.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/write-queue.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,EAAC,MAAM,SAAS,CAAC;AAE9B,OAAO,EAAC,cAAc,EAAC,MAAM,mBAAmB,CAAC;AAKjD,MAAM,MAAM,cAAc,GAAG;IAC3B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;;;;;;;;;;;;;;OAeG;IACH,YAAY,EAAE,MAAM,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;CAC5C,CAAC;AAEF,MAAM,CAAC,OAAO,OAAO,UAAU,CAAC,CAAC,SAAS,cAAc,CAAE,SAAQ,KAAK,CAAC,CAAC,CAAC;IACxE,OAAO,CAAC,UAAU,CAAC,CAAiB;IACpC,OAAO,CAAC,cAAc,CAAiB;IAChC,YAAY,EAAE,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAQ;IAC1C,OAAO,EAAE;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAC,CAAM;IACtC,iBAAiB,EAAE,MAAM,CAAC;IAC1B,gBAAgB,EAAE,MAAM,CAAC;gBAG9B,cAAc,EAAE,cAAc,EAC9B,iBAAiB,GAAE,MAAa,EAChC,gBAAgB,GAAE,MAAY;IAQ1B,OAAO,CAAC,GAAG,EAAE,CAAC,EAAE,gBAAgB,GAAE,OAAe;IAgBvD,cAAc;IAId,aAAa;IAMP,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAQ3B,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;YAKjB,OAAO;IAsBrB,OAAO,CAAC,aAAa;CAWtB"}
|
|
@@ -2,15 +2,17 @@ import { Queue } from "./queue.js";
|
|
|
2
2
|
import process from 'process';
|
|
3
3
|
const MEMORY_LIMIT = 4 * 1024 * 1024 * 1024;
|
|
4
4
|
export default class WriteQueue extends Queue {
|
|
5
|
-
constructor() {
|
|
6
|
-
let listeningInterval = arguments.length >
|
|
7
|
-
let writeConcurrency = arguments.length >
|
|
5
|
+
constructor(conversionDump) {
|
|
6
|
+
let listeningInterval = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 2000;
|
|
7
|
+
let writeConcurrency = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 400;
|
|
8
8
|
super();
|
|
9
9
|
this.intervalId = void 0;
|
|
10
|
+
this.conversionDump = void 0;
|
|
10
11
|
this.writePromise = null;
|
|
11
12
|
this.fileMap = {};
|
|
12
13
|
this.listeningInterval = void 0;
|
|
13
14
|
this.writeConcurrency = void 0;
|
|
15
|
+
this.conversionDump = conversionDump;
|
|
14
16
|
this.listeningInterval = listeningInterval;
|
|
15
17
|
this.writeConcurrency = writeConcurrency;
|
|
16
18
|
}
|
|
@@ -55,6 +57,7 @@ export default class WriteQueue extends Queue {
|
|
|
55
57
|
while (this.length) {
|
|
56
58
|
const promises = [];
|
|
57
59
|
const archiveKeys = [];
|
|
60
|
+
const changedRecords = [];
|
|
58
61
|
for (let i = 0; i < this.writeConcurrency; i++) {
|
|
59
62
|
const item = this.dequeue();
|
|
60
63
|
if (!item) {
|
|
@@ -62,14 +65,23 @@ export default class WriteQueue extends Queue {
|
|
|
62
65
|
}
|
|
63
66
|
const {
|
|
64
67
|
archiveKey,
|
|
68
|
+
sourceId,
|
|
69
|
+
outputId,
|
|
70
|
+
resourceType,
|
|
65
71
|
writePromise
|
|
66
72
|
} = item;
|
|
67
73
|
archiveKeys.push(archiveKey);
|
|
74
|
+
changedRecords.push({
|
|
75
|
+
sourceId,
|
|
76
|
+
outputId,
|
|
77
|
+
resourceType
|
|
78
|
+
});
|
|
68
79
|
const promise = writePromise();
|
|
69
80
|
promises.push(promise);
|
|
70
81
|
}
|
|
71
82
|
const writeResults = await Promise.allSettled(promises);
|
|
72
83
|
this.updateFileMap(archiveKeys, writeResults);
|
|
84
|
+
await this.conversionDump.updateConvertedTilesDump(changedRecords, writeResults);
|
|
73
85
|
}
|
|
74
86
|
}
|
|
75
87
|
updateFileMap(archiveKeys, writeResults) {
|