@xbibzlibrary/base64
v1.0.3
Published
Base64 Encoding/Decoding Library with File Preview Support
Maintainers
Readme
🚀 Base64 Tools
Advanced Base64 Encoding Library with File Preview Support
Transform any file into base64 with style ✨
Features • Quick Start • Documentation • Demo • Support

🎯 What Makes This Special?
This isn't just another base64 library. Built with modern JavaScript, it delivers professional-grade encoding and decoding with an elegant API that developers actually enjoy using.
// That's all it takes
const base64 = new XbibzBase64();
const result = await base64.encodeFile(yourFile);
console.log(result.dataURI); // Ready to use!✨ Features
🎨 Multi-Format Support
Handle images, videos, audio, archives, and virtually any file type with intelligent MIME detection and validation.
📦 Batch Processing
Process multiple files simultaneously with a sophisticated queue system that maintains performance and reliability.
🔍 Visual Previews
Generate real-time previews for images, videos, and audio with comprehensive metadata extraction.
⚡ Performance First
Optimized for speed with built-in monitoring, intelligent caching, and efficient memory management.
🛡️ Error Resilience
Comprehensive error handling with detailed logging and graceful fallbacks for edge cases.
🌐 Universal Compatibility
Works seamlessly across all modern browsers with zero dependencies.
📊 Smart Analytics
Built-in performance monitoring and detailed statistics for optimization insights.
🎁 Production Ready
Battle-tested code with thorough validation and professional-grade reliability.
🚀 Quick Start
Installation via CDN
<script src="https://cdn.jsdelivr.net/npm/@xbibzlibrary/[email protected]/base64.js"></script>Basic Usage
// Initialize the library
const base64 = new XbibzBase64();
// Encode a single file
const fileInput = document.querySelector('input[type="file"]');
fileInput.addEventListener('change', async (e) => {
const file = e.target.files[0];
const result = await base64.encodeFile(file);
console.log('Encoded successfully!');
console.log('Data URI:', result.dataURI);
console.log('Base64 String:', result.base64String);
console.log('File Info:', result.fileName, result.fileSize);
});
// Decode base64 back to file
const decoded = base64.decodeBase64(result.dataURI);
console.log('Original file restored!', decoded.blob);📖 Documentation
Core Methods
encodeFile(file)
Encode a single file to base64 format.
const result = await base64.encodeFile(file);
// Returns: {
// dataURI: "data:image/png;base64,iVBOR...",
// base64String: "iVBOR...",
// fileName: "image.png",
// mimeType: "image/png",
// fileSize: 45632,
// encodedSize: 60844
// }encodeFiles(files)
Encode multiple files with progress tracking.
const results = await base64.encodeFiles([file1, file2, file3]);
// Returns array of encoded file objectsdecodeBase64(base64String, mimeType, fileName)
Decode base64 string back to file.
const result = base64.decodeBase64(
"data:image/png;base64,iVBOR...",
null, // Auto-detect
"decoded_image.png"
);
// Returns: { blob, fileName, mimeType, fileSize }addToQueue(files)
Add files to processing queue.
await base64.addToQueue([file1, file2, file3]);
const status = base64.getQueueStatus();processQueue()
Process all queued files.
const results = await base64.processQueue();
console.log(`${results.successfulCount} files processed`);Utility Methods
// Get library information
const info = base64.getLibraryInfo();
// Get queue status
const status = base64.getQueueStatus();
// Access logger
const logger = base64.getLogger();
logger.log('info', 'Custom log message');
// Clear queue
const cleared = base64.clearQueue();🎨 Supported File Types
🖼️ Images
JPEG • PNG • GIF • WebP BMP • SVG • ICO • TIFF
🎬 Videos
MP4 • WebM • OGG AVI • MOV • WMV • FLV
🎵 Audio
MP3 • WAV • OGG AAC • FLAC • M4A • WMA
📦 Archives
ZIP • RAR • 7Z TAR • GZIP • BZ2
Plus support for documents (PDF, DOC, XLS), text files, and virtually any file format.
🎮 Live Demo
Experience the library in action with our interactive demo page featuring:
- 🎯 Drag & drop file upload
- 📊 Real-time processing statistics
- 🖼️ Visual file previews
- 📝 Activity logging
- ⚡ Queue management
- 📥 Download encoded files
View Live Demo (Replace with your actual demo URL)
💡 Advanced Examples
Batch Processing with Progress
const files = Array.from(fileInput.files);
// Add to queue
await base64.addToQueue(files);
// Monitor queue
const status = base64.getQueueStatus();
console.log(`Queue size: ${status.queueSize}`);
// Process with results
const results = await base64.processQueue();
results.successful.forEach(file => {
console.log(`✓ ${file.fileName} encoded successfully`);
});Image Preview Generation
const imageFile = document.querySelector('input[type="file"]').files[0];
const encoded = await base64.encodeFile(imageFile);
// Create instant preview
const img = document.createElement('img');
img.src = encoded.dataURI;
document.body.appendChild(img);Error Handling
try {
const result = await base64.encodeFile(file);
console.log('Success:', result);
} catch (error) {
console.error('Encoding failed:', error.message);
// Access detailed logs
const logs = base64.getLogger().getLogs();
logs.filter(log => log.level === 'error').forEach(log => {
console.error(log.message);
});
}🔧 Configuration
The library supports configuration through constructor options:
const base64 = new XbibzBase64({
maxFileSize: 50 * 1024 * 1024, // 50MB limit
enableLogging: true,
autoProcess: false
});📊 Performance
Optimized for speed and efficiency:
- ⚡ Fast encoding using native browser APIs
- 💾 Memory efficient with chunked processing for large files
- 🔄 Async operations preventing UI blocking
- 📈 Scalable queue system for batch operations
🛠️ Browser Support
Works on all modern browsers:
- ✅ Chrome 90+
- ✅ Firefox 88+
- ✅ Safari 14+
- ✅ Edge 90+
- ✅ Opera 76+
📦 File Size
- Minified: ~12KB
- Gzipped: ~4KB
- Zero dependencies
🤝 Contributing
We welcome contributions! Feel free to:
- 🐛 Report bugs
- 💡 Suggest features
- 📝 Improve documentation
- 🔧 Submit pull requests
📄 License
MIT License - feel free to use in personal and commercial projects.
👨💻 Author
Xbibz Official
🌟 Support
If you find this library helpful, consider:
Made with ❤️ by Xbibz Official
