@toast-studios/asset-manager
A powerful React Native asset management library with intelligent caching, network-aware downloading, and dynamic manifest loading.
🚀 Features
- Dynamic Manifest Loading - Fetch manifests from URLs with app versioning and localization
- Network-Aware Downloads - Intelligent downloading based on network conditions
- Smart Caching - Automatic cache management (default 500MB)
- High-Performance Batching - 90%+ reduction in I/O operations through intelligent batching
- Asset Validation - SHA-256 hash verification
- Auto Cleanup - Automatic cleanup of old assets
- TypeScript Support - Full type definitions included
- Production Ready - Battle-tested in production
📦 Installation
npm install @toast-studios/asset-manager react-native-fs @react-native-community/netinfo react-native-device-info @react-native-async-storage/async-storage
🔧 Quick Start
import { ToastAssetManager } from '@toast-studios/asset-manager';
const assetManager = new ToastAssetManager({
basePath: '/assets',
manifestUrl: 'https://api.yourapp.com/manifest',
appVersion: '1.2.3',
appLanguage: 'en'
});
await assetManager.start();
const assetPath = await assetManager.getAsset('my-video.mp4');
📖 Configuration
interface AssetManagerConfig {
basePath: string;
appVersion?: string;
manifestUrl?: string;
appLanguage?: string;
maxConcurrentDownloads?: number;
retryAttempts?: number;
retryDelay?: number;
cacheLimit?: number;
customHeaders?: Record<string, string>;
enableLogging?: boolean;
}
🌐 Dynamic Manifest Loading
const assetManager = new ToastAssetManager({
basePath: '/assets',
manifestUrl: 'https://api.yourapp.com/manifest',
appVersion: '1.2.3',
appLanguage: 'en'
});
Manifest Format:
{
"version": "1.0.0",
"bundles": [{
"id": "essential-assets",
"url": "https://cdn.yourapp.com/assets/essential.zip",
"size": 1024000,
"isCritical": true,
"hash": "sha256-abc123...",
"assets": [{
"id": "logo.png",
"filename": "logo.png",
"type": "image",
"size": 5000,
"hash": "sha256-def456..."
}]
}]
}
📱 React Native Example
import React, { useState, useEffect } from 'react';
import { ToastAssetManager } from '@toast-studios/asset-manager';
const AssetComponent = () => {
const [progress, setProgress] = useState(0);
const [assetManager, setAssetManager] = useState(null);
useEffect(() => {
const manager = new ToastAssetManager({
basePath: '/assets',
manifestUrl: 'https://api.yourapp.com/manifest',
appVersion: '1.0.0'
});
manager.onProgress((progress) => setProgress(progress.progress));
manager.start().then(() => setAssetManager(manager));
}, []);
return (
<View>
<Text>Progress: {progress}%</Text>
</View>
);
};
🔧 Production Configurations
Enterprise:
new ToastAssetManager({
basePath: '/assets',
manifestUrl: 'https://cdn.yourapp.com/manifest',
appVersion: '2.1.0',
cacheLimit: 1024 * 1024 * 1024,
retryAttempts: 5,
customHeaders: { 'Authorization': 'Bearer token' }
});
High-Performance:
new ToastAssetManager({
basePath: '/assets',
manifestUrl: 'https://api.yourapp.com/manifest',
maxConcurrentDownloads: 5,
cacheLimit: 2048 * 1024 * 1024,
retryDelay: 500
});
🛠 Key Methods
await assetManager.start();
await assetManager.start(manifest);
const path = await assetManager.getAsset('id');
const asset = assetManager.getAsset('id');
const count = await assetManager.cleanup();
await assetManager.destroy();
assetManager.onProgress((progress) => {
console.log(`${progress.progress}% - ${progress.status}`);
});
await assetManager.flushStorage();
const stats = assetManager.getStorageBatchingStats();
⚡ Performance Optimization
The asset manager uses intelligent batching to dramatically reduce disk I/O operations:
Before (v1.1): Every asset save = 2 disk writes
After (v1.2): Multiple saves batched into 2 disk writes within 1-second windows
Performance Impact:
- 10 assets: 90% fewer I/O operations
- 100 assets: 99% fewer I/O operations
- 1000 assets: 99.9% fewer I/O operations
await assetManager.start();
await assetManager.flushStorage();
const stats = assetManager.getStorageBatchingStats();
console.log(`Pending updates: ${stats.pendingAssetUpdates}`);
console.log(`Batching active: ${stats.hasPendingTimer}`);
🔒 Enterprise Features
- CDN Integration - Optimized for global content delivery
- Multi-language Support - Localization through language parameters
- Version Management - App version-based manifest fetching
- HTTPS Security - Secure downloads with hash verification
- Memory Management - Intelligent cache limits
- Background Processing - Non-blocking operations
📄 License
Commercial License - © Toast Studios
🤝 Support
Technical Support: Implementation assistance and documentation
Enterprise Services: Priority support, custom features, training
Contact: Toast Studios team for licensing and support
Powered by Toast Studios