|
|
@ -272,13 +272,13 @@ export class ApiFileManager { |
|
|
|
private uncompressTGS = (bytes: Uint8Array, fileName: string) => { |
|
|
|
private uncompressTGS = (bytes: Uint8Array, fileName: string) => { |
|
|
|
//this.log('uncompressTGS', bytes, bytes.slice().buffer);
|
|
|
|
//this.log('uncompressTGS', bytes, bytes.slice().buffer);
|
|
|
|
// slice нужен потому что в uint8array - 5053 length, в arraybuffer - 5084
|
|
|
|
// slice нужен потому что в uint8array - 5053 length, в arraybuffer - 5084
|
|
|
|
return cryptoWorker.invokeCrypto('gzipUncompress', bytes.slice().buffer, true) as Promise<string>; |
|
|
|
return cryptoWorker.invokeCrypto('gzipUncompress', bytes.slice().buffer, false) as Promise<Uint8Array>; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
private uncompressTGV = (bytes: Uint8Array, fileName: string) => { |
|
|
|
private uncompressTGV = (bytes: Uint8Array, fileName: string) => { |
|
|
|
//this.log('uncompressTGS', bytes, bytes.slice().buffer);
|
|
|
|
//this.log('uncompressTGS', bytes, bytes.slice().buffer);
|
|
|
|
// slice нужен потому что в uint8array - 5053 length, в arraybuffer - 5084
|
|
|
|
// slice нужен потому что в uint8array - 5053 length, в arraybuffer - 5084
|
|
|
|
return cryptoWorker.invokeCrypto('gzipUncompress', bytes.slice().buffer, true) as Promise<string>; |
|
|
|
return cryptoWorker.invokeCrypto('gzipUncompress', bytes.slice().buffer, false) as Promise<Uint8Array>; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
private convertWebp = (bytes: Uint8Array, fileName: string) => { |
|
|
|
private convertWebp = (bytes: Uint8Array, fileName: string) => { |
|
|
@ -408,11 +408,11 @@ export class ApiFileManager { |
|
|
|
deferred.resolve(blob); |
|
|
|
deferred.resolve(blob); |
|
|
|
}).catch(() => { |
|
|
|
}).catch(() => { |
|
|
|
//this.log('not cached', fileName);
|
|
|
|
//this.log('not cached', fileName);
|
|
|
|
const fileWriterPromise = fileStorage.getFileWriter(fileName, mimeType); |
|
|
|
const limit = options.limitPart || this.getLimitPart(size); |
|
|
|
|
|
|
|
const fileWriterPromise = fileStorage.getFileWriter(fileName, size || limit, mimeType); |
|
|
|
|
|
|
|
|
|
|
|
fileWriterPromise.then((fileWriter) => { |
|
|
|
fileWriterPromise.then((fileWriter) => { |
|
|
|
cacheFileWriter = fileWriter; |
|
|
|
cacheFileWriter = fileWriter; |
|
|
|
const limit = options.limitPart || this.getLimitPart(size); |
|
|
|
|
|
|
|
let offset: number; |
|
|
|
let offset: number; |
|
|
|
let startOffset = 0; |
|
|
|
let startOffset = 0; |
|
|
|
let writeFilePromise: CancellablePromise<void> = Promise.resolve(), |
|
|
|
let writeFilePromise: CancellablePromise<void> = Promise.resolve(), |
|
|
@ -422,7 +422,7 @@ export class ApiFileManager { |
|
|
|
|
|
|
|
|
|
|
|
//console.error('maxRequests', maxRequests);
|
|
|
|
//console.error('maxRequests', maxRequests);
|
|
|
|
|
|
|
|
|
|
|
|
const processDownloaded = async(bytes: Uint8Array, offset: number) => { |
|
|
|
const processDownloaded = async(bytes: Uint8Array) => { |
|
|
|
if(process) { |
|
|
|
if(process) { |
|
|
|
//const perf = performance.now();
|
|
|
|
//const perf = performance.now();
|
|
|
|
const processed = await process(bytes, fileName); |
|
|
|
const processed = await process(bytes, fileName); |
|
|
@ -473,13 +473,18 @@ export class ApiFileManager { |
|
|
|
deferred.notify({done, offset, total: size}); |
|
|
|
deferred.notify({done, offset, total: size}); |
|
|
|
//}
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
const processedResult = await processDownloaded(bytes, offset); |
|
|
|
await writeFilePromise; |
|
|
|
checkCancel(); |
|
|
|
checkCancel(); |
|
|
|
|
|
|
|
|
|
|
|
await writeFilePromise; |
|
|
|
await fileWriter.write(bytes, offset); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(isFinal && process) { |
|
|
|
|
|
|
|
const bytes = fileWriter.getParts(); |
|
|
|
|
|
|
|
const processedResult = await processDownloaded(bytes); |
|
|
|
checkCancel(); |
|
|
|
checkCancel(); |
|
|
|
|
|
|
|
|
|
|
|
await fileManager.write(fileWriter, processedResult); |
|
|
|
fileWriter.replaceParts(processedResult); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
writeFileDeferred.resolve(); |
|
|
|
writeFileDeferred.resolve(); |
|
|
@ -487,7 +492,12 @@ export class ApiFileManager { |
|
|
|
if(isFinal) { |
|
|
|
if(isFinal) { |
|
|
|
resolved = true; |
|
|
|
resolved = true; |
|
|
|
|
|
|
|
|
|
|
|
deferred.resolve(fileWriter.finalize(size < MAX_FILE_SAVE_SIZE)); |
|
|
|
const realSize = size || bytes.byteLength; |
|
|
|
|
|
|
|
if(!size) { |
|
|
|
|
|
|
|
fileWriter.trim(realSize); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
deferred.resolve(fileWriter.finalize(realSize < MAX_FILE_SAVE_SIZE)); |
|
|
|
} |
|
|
|
} |
|
|
|
} catch(err) { |
|
|
|
} catch(err) { |
|
|
|
errorHandler(err as Error); |
|
|
|
errorHandler(err as Error); |
|
|
|