🚧 Speed up development by caching downloaded files
This commit is contained in:
parent
9fc68f105a
commit
0b5348e819
2 changed files with 61 additions and 1 deletions
|
@ -1,5 +1,5 @@
|
||||||
import getManifest from './ssn/getManifest';
|
import getManifest from './ssn/getManifest';
|
||||||
import getPatch from './ssn/getPatch';
|
import getPatch from './ssn/getPatchTest';
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
//----- PATCHMANIFEST -----
|
//----- PATCHMANIFEST -----
|
||||||
|
|
60
src/ssn/getPatchTest.ts
Normal file
60
src/ssn/getPatchTest.ts
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
import downloadUrlContents from '../cdn/downloadUrlContents';
|
||||||
|
import getUrlContents from '../cdn/getUrlContents';
|
||||||
|
import { Product } from '../interfaces/ISettings';
|
||||||
|
import { SsnDiffType } from '../interfaces/ISsnFileEntry';
|
||||||
|
import extractFileStream from './extractFileStream';
|
||||||
|
import getSolidpkg from './getSolidpkg';
|
||||||
|
import readSsnFile from './reader/readSsnFile';
|
||||||
|
import getFileFromDisks from './streams/getFileFromDisks';
|
||||||
|
import streamToArrayBuffer from './streams/streamToArrayBuffer';
|
||||||
|
import verifyPatch from './verify/verifyPatch';
|
||||||
|
|
||||||
|
export default async function getPatch(product: Product, from: number, to: number) {
|
||||||
|
const solidpkg = await getSolidpkg(product, from, to);
|
||||||
|
console.debug(solidpkg.files);
|
||||||
|
|
||||||
|
function createUrlObject(fileName: string) {
|
||||||
|
return { host: 'cdn-patch.swtor.com', path: `/patch/${product}/${product}_${from}to${to}/${fileName}` };
|
||||||
|
}
|
||||||
|
|
||||||
|
//start download, making sure that .zip file downloads first
|
||||||
|
const indexOfLastFile = solidpkg.files.length - 1;
|
||||||
|
const zipFile = getUrlContents(createUrlObject(solidpkg.files[indexOfLastFile].name));
|
||||||
|
//const diskFiles = solidpkg.files.slice(0, indexOfLastFile).map((file) => downloadUrlContents(createUrlObject(file.name)));
|
||||||
|
|
||||||
|
//we can parse the file entries as soon as the .zip file is downloaded
|
||||||
|
const fileEntries = readSsnFile(await zipFile);
|
||||||
|
console.debug(fileEntries);
|
||||||
|
|
||||||
|
//Verify file entries
|
||||||
|
verifyPatch(fileEntries, product, from);
|
||||||
|
|
||||||
|
//Then we need to wait for disks to finish download before we can extract individual files
|
||||||
|
//TODO: we can optimize this to already extract some files as soon as their relevant parts are downloaded
|
||||||
|
//const diskFilenames = await Promise.all(diskFiles);
|
||||||
|
const diskFilenames = ['../assets_swtor_main_-1to0.z01'];
|
||||||
|
//const dvArray = bufferArray.map((buffer) => new DataView(buffer));
|
||||||
|
|
||||||
|
//TODO: Verify that downloaded files match the hash in `solidpkg.pieces`
|
||||||
|
|
||||||
|
//Extract newly added files
|
||||||
|
fileEntries.filter((file) => file.diffType === SsnDiffType.NewFile && file.diskNumberStart === 0).forEach(async (file) => {
|
||||||
|
const fileStream = await getFileFromDisks(diskFilenames, { diskStart: file.diskNumberStart, offset: file.offset, storedSize: file.compressedSize });
|
||||||
|
const fileContents = extractFileStream(file, fileStream);
|
||||||
|
console.debug(await streamToArrayBuffer(fileContents));
|
||||||
|
//TODO: need to write to disk
|
||||||
|
});
|
||||||
|
|
||||||
|
//Extract changed files
|
||||||
|
fileEntries.filter((file) => file.diffType === SsnDiffType.Changed && file.diskNumberStart === 0).forEach(async (file) => {
|
||||||
|
const fileStream = await getFileFromDisks(diskFilenames, { diskStart: file.diskNumberStart, offset: file.offset, storedSize: file.compressedSize });
|
||||||
|
const fileContents = extractFileStream(file, fileStream);
|
||||||
|
console.debug(await streamToArrayBuffer(fileContents));
|
||||||
|
//TODO: need to apply diffing, then write to disk
|
||||||
|
});
|
||||||
|
|
||||||
|
//Need to delete deleted files
|
||||||
|
fileEntries.filter((file) => file.diffType === SsnDiffType.Deleted).forEach((file) => {
|
||||||
|
//TODO: need to delete file
|
||||||
|
});
|
||||||
|
}
|
Loading…
Reference in a new issue