Asper Header  1.0.14
The header injector extension
Loading...
Searching...
No Matches
lazyFileLoad.ts File Reference

Advanced lazy loading file system utility with intelligent caching and type safety. More...

Go to the source code of this file.

Data Structures

class  LazyFileLoader< T=any >
 

Variables

import *as fsp from fs promises
 
import *as path from path
 
 import { logger } from './logger'
 

Detailed Description

Advanced lazy loading file system utility with intelligent caching and type safety.

Author
Henry Letellier
Version
1.0.10
Since
1.0.0
Date
2025

This module implements a sophisticated lazy loading file system utility that serves as the foundation for efficient resource management throughout the AsperHeader extension. It provides intelligent caching, automatic content parsing, flexible path resolution, and comprehensive error handling while maintaining full type safety through generics.

Design Philosophy:

  • Performance First: Minimize file I/O through intelligent caching strategies
  • Type Safety: Leverage TypeScript generics for compile-time type checking
  • Flexibility: Support diverse file formats and path resolution patterns
  • Error Resilience: Comprehensive error handling with graceful degradation
  • Resource Efficiency: Memory-conscious caching with selective retention

Core Features:

  • Lazy Loading: Files loaded only when first accessed, reducing startup time
  • Intelligent Caching: In-memory caching with cache invalidation and refresh
  • Format Flexibility: Support for JSON, JSONC, plain text, and custom formats
  • Path Resolution: Automatic resolution of relative and absolute paths
  • Type Safety: Generic type parameters ensure compile-time content validation
  • Error Recovery: Graceful handling of missing files, parse errors, and I/O failures

File Format Support:

  • JSON Files: Automatic parsing with error handling and validation
  • JSONC Files: JSON with comments support for configuration files
  • Text Files: Raw text content with encoding detection
  • Custom Formats: Extensible parsing system for specialized file types
  • Binary Files: Basic support for binary content with appropriate type handling

Caching Strategy:

  • Memory Caching: Parsed content cached in memory for subsequent access
  • Invalidation: Manual cache invalidation and automatic refresh mechanisms
  • Memory Management: Intelligent cache size management and cleanup
  • Performance Monitoring: Optional cache hit/miss statistics for optimization

Integration Points: This utility serves as the backbone for resource loading across the extension:

  • Configuration Loading: Language definitions and formatting rules
  • Asset Management: ASCII art files and logo collections
  • Template System: Header templates and message definitions
  • Internationalization: Message files and localization resources

Error Handling Strategy:

  • File Not Found: Graceful fallback to default content or error reporting
  • Parse Errors: Detailed error messages with context information
  • Permission Issues: Clear error reporting for filesystem access problems
  • Network Issues: Timeout handling for remote file access (future enhancement)

Definition in file lazyFileLoad.ts.

Variable Documentation

◆ import

import { logger } from './logger'

Definition at line 78 of file lazyFileLoad.ts.

◆ path

import* as path from path

Definition at line 77 of file lazyFileLoad.ts.

◆ promises

import* as fsp from fs promises

Definition at line 76 of file lazyFileLoad.ts.