UNPKG

digitaltwin-core

Version:

Minimalist framework to collect and handle data in a Digital Twin project

66 lines 2.79 kB
import type { StorageService } from '../storage/storage_service.js'; /** * Result of extracting and storing a ZIP archive */ export interface ExtractedArchiveResult { /** The root/main file path (e.g., 'tileset.json') */ root_file?: string; /** Total number of files extracted */ file_count: number; } /** * Extracts the content of a zip file as a stream (for large files) * @param zipBuffer - The content of the zip file as Buffer * @returns A generator yielding tuples containing the name and content of each file in the zip file */ export declare function extractZipContentStream(zipBuffer: Buffer): AsyncGenerator<[string, string | Buffer]>; /** * Converts a zip file to a dictionary containing all files and their contents * @param zipBuffer - The content of the zip file as Buffer * @returns A dictionary containing the content of the zip file */ export declare function zipToDict(zipBuffer: Buffer): Promise<Record<string, string | Buffer>>; /** * Detects the root file for 3D Tiles tilesets * Looks for tileset.json or similar entry point files * @param files - List of file paths in the archive * @returns The path to the root file, or undefined if not found */ export declare function detectTilesetRootFile(files: string[]): string | undefined; /** * Normalizes file paths from ZIP archives * Removes leading directory if all files share the same root folder * @param files - Original file paths from the archive * @returns Normalized file paths (original -> normalized) */ export declare function normalizeArchivePaths(files: string[]): Map<string, string>; /** * Extracts a ZIP archive and stores each file individually using the storage service. * * This function: * 1. Extracts all files from the ZIP * 2. Normalizes paths (removes common root directory if present) * 3. Stores each file using the storage service with a unique base path * 4. Returns the root file path and file count * * Files are uploaded in parallel batches for performance. * * @param zipBuffer - The ZIP file content as a Buffer * @param storage - The storage service to use for saving files * @param basePath - Base path/folder for storing extracted files (e.g., 'tilesets/1234567890') * @returns ExtractedArchiveResult with root file and file count * * @example * ```typescript * const result = await extractAndStoreArchive(zipBuffer, storage, 'tilesets/1234567890') * // result.root_file = 'tileset.json' * // result.file_count = 42 * * // Files are stored at: * // tilesets/1234567890/tileset.json * // tilesets/1234567890/tiles/tile_0.b3dm * // etc. * ``` */ export declare function extractAndStoreArchive(zipBuffer: Buffer, storage: StorageService, basePath: string): Promise<ExtractedArchiveResult>; //# sourceMappingURL=zip_utils.d.ts.map