feat: zip reader

This commit is contained in:
TrèsAbhi committed 2025-11-29 14:34:06 -06:00
1 parent 2101dba7c6
commit f33a73e1bb
9 files changed
+59 -5

No files matched your search

+1
View File
@@ -31,6 +31,7 @@
"steam-user": "^5.2.3",
"three": "^0.180.0",
"ts-proto": "^2.7.7",
"unzipit": "^1.4.3",
"yaml": "^2.8.1"
},
"private": true,
@@ -1,5 +1,5 @@
import { assertSecret } from "@blitzkit/core";
import { SteamVFS } from "../core/steam/vfs";
import { SteamVFS } from "../core/vfs/vfs";
const APP = 444200;
const DEPOT = 444202;
@@ -6,7 +6,7 @@ import {
} from "@blitzkit/core";
import { Accessor, Document, Node, Scene } from "@gltf-transform/core";
import { times } from "lodash-es";
import { SteamVFS } from "../steam/vfs";
import { SteamVFS } from "../vfs/vfs";
import {
vertexAttributeGLTFName,
vertexAttributeGltfVectorSizes,
@@ -9,7 +9,7 @@ import { Document, Material, Node, Scene } from "@gltf-transform/core";
import { dedup, prune } from "@gltf-transform/functions";
import { times } from "lodash-es";
import { dirname } from "path";
import { SteamVFS } from "../../steam/vfs";
import { SteamVFS } from "../../vfs/vfs";
import { readBaseColor } from "../readBaseColor";
import { readNormal } from "../readNormal";
import { readRoughnessMetallic } from "../readRoughnessMetallic";
@@ -0,0 +1,3 @@
export abstract class AbstractVFS {
abstract init(): Promise<AbstractVFS>;
}
@@ -3,6 +3,7 @@ import { XMLParser } from "fast-xml-parser";
import { normalize } from "path/posix";
import SteamUser, { EConnectionProtocol } from "steam-user";
import { parse } from "yaml";
import { AbstractVFS } from "./abstract";
interface SteamManifestFile {
chunks: {
@@ -33,7 +34,7 @@ interface SteamManifest {
crc_clear: number;
}
export class SteamVFS {
export class SteamVFS extends AbstractVFS {
private steam = new SteamUser({ protocol: EConnectionProtocol.TCP });
private textDecoder = new TextDecoder();
private xmlParser = new XMLParser();
@@ -45,7 +46,9 @@ export class SteamVFS {
private password: string,
private app: number,
private depot: number
) {}
) {
super();
}
async init() {
this.steam.logOn({
+21
View File
@@ -0,0 +1,21 @@
import { HTTPRangeReader, unzip, ZipEntry } from "unzipit";
import { AbstractVFS } from "./abstract";
export class ZipVFS extends AbstractVFS {
entries: Record<string, ZipEntry> = {};
constructor(private url: string, private root = "app/") {
super();
}
async init() {
const reader = new HTTPRangeReader(this.url);
const { entries } = await unzip(reader);
for (const entry of Object.values(entries)) {
this.entries[entry.name.slice(this.root.length)] = entry;
}
return this;
}
}
@@ -0,0 +1,21 @@
---
import type { GetStaticPaths } from "astro";
import { api } from "../../../core/api/dynamic";
export const getStaticPaths = (async () => {
const { tanks } = await api.tanks();
return tanks.map((tank) => ({
params: { slug: tank.slug },
props: { id: tank.id },
}));
}) satisfies GetStaticPaths;
const { id } = Astro.props;
---
<h1>Tank {id}</h1>
<code>
<pre>{JSON.stringify(await api.tank(id), null, 2)}</pre>
</code>