|
| 1 | +# Enhanced s5.js Demos |
| 2 | + |
| 3 | +This directory contains comprehensive demonstrations of Enhanced s5.js capabilities, showing you how to build decentralized applications with S5 storage. |
| 4 | + |
| 5 | +## Installation |
| 6 | + |
| 7 | +To run these demos, first install the Enhanced s5.js package: |
| 8 | + |
| 9 | +```bash |
| 10 | +npm install @julesl23/s5js@beta |
| 11 | +``` |
| 12 | + |
| 13 | +## Prerequisites |
| 14 | + |
| 15 | +- **Node.js**: Version 20 or higher |
| 16 | +- **Modern Browser**: For browser-based demos (Chrome, Firefox, Safari, Edge) |
| 17 | + |
| 18 | +## Available Demos |
| 19 | + |
| 20 | +### 1. Getting Started Tutorial (`getting-started-tutorial.js`) |
| 21 | + |
| 22 | +**What this demo shows:** |
| 23 | +Comprehensive walkthrough from setup to production deployment, covering all major Enhanced s5.js features in a single tutorial. |
| 24 | + |
| 25 | +**Topics covered:** |
| 26 | +- S5 instance setup and peer connections |
| 27 | +- Identity management with seed phrases |
| 28 | +- Portal registration |
| 29 | +- File system operations (put, get, list, delete, getMetadata) |
| 30 | +- Media processing (image upload with thumbnails) |
| 31 | +- Directory utilities (walker, batch operations, pagination) |
| 32 | +- Encryption for private data |
| 33 | +- Advanced CID API for content-addressed storage |
| 34 | +- HAMT sharding for large directories |
| 35 | + |
| 36 | +**Run it:** |
| 37 | +```bash |
| 38 | +cd demos |
| 39 | +node getting-started-tutorial.js |
| 40 | +``` |
| 41 | + |
| 42 | +**Perfect for:** Developers new to Enhanced s5.js who want to understand the complete workflow. |
| 43 | + |
| 44 | +### 2. Media Processing Demos (`media/`) |
| 45 | + |
| 46 | +**What these demos show:** |
| 47 | +Advanced media processing capabilities including thumbnail generation, metadata extraction, and progressive rendering. |
| 48 | + |
| 49 | +See [`media/README.md`](./media/README.md) for detailed documentation of: |
| 50 | +- Performance benchmarking (WASM vs Canvas strategies) |
| 51 | +- Pipeline setup and initialization |
| 52 | +- Metadata extraction from JPEG, PNG, WebP, GIF, BMP |
| 53 | +- Code-splitting and bundle optimization |
| 54 | +- Integration testing |
| 55 | + |
| 56 | +**Run them:** |
| 57 | +```bash |
| 58 | +cd demos/media |
| 59 | +node demo-metadata.js # Extract metadata from images |
| 60 | +node demo-pipeline.js # Show pipeline initialization |
| 61 | +node benchmark-media.js # Performance benchmarks |
| 62 | +``` |
| 63 | + |
| 64 | +**Perfect for:** Applications that need to process, analyze, or optimize images before uploading to S5. |
| 65 | + |
| 66 | +## Key Features Demonstrated |
| 67 | + |
| 68 | +### Path-based API |
| 69 | +Simple filesystem-like operations: |
| 70 | +```javascript |
| 71 | +import { S5 } from '@julesl23/s5js'; |
| 72 | + |
| 73 | +const s5 = await S5.create(); |
| 74 | +await s5.fs.put('home/documents/hello.txt', 'Hello, S5!'); |
| 75 | +const content = await s5.fs.get('home/documents/hello.txt'); |
| 76 | +``` |
| 77 | + |
| 78 | +### HAMT Sharding |
| 79 | +Automatic directory sharding for millions of entries (activates at 1000+ entries): |
| 80 | +```javascript |
| 81 | +// Efficiently handles large directories |
| 82 | +for await (const item of s5.fs.list('home/photos', { limit: 100 })) { |
| 83 | + console.log(item.name, item.size); |
| 84 | +} |
| 85 | +``` |
| 86 | + |
| 87 | +### Media Processing |
| 88 | +Thumbnail generation and metadata extraction: |
| 89 | +```javascript |
| 90 | +import { MediaProcessor } from '@julesl23/s5js/media'; |
| 91 | + |
| 92 | +const result = await s5.fs.putImage('gallery/photo.jpg', imageBlob, { |
| 93 | + generateThumbnail: true, |
| 94 | + thumbnailMaxWidth: 200 |
| 95 | +}); |
| 96 | +``` |
| 97 | + |
| 98 | +### Advanced CID API |
| 99 | +Content-addressed storage for power users: |
| 100 | +```javascript |
| 101 | +import { FS5Advanced, formatCID } from '@julesl23/s5js/advanced'; |
| 102 | + |
| 103 | +const advanced = new FS5Advanced(s5.fs); |
| 104 | +const cid = await advanced.pathToCID('home/data.txt'); |
| 105 | +console.log(formatCID(cid, 'base32')); |
| 106 | +``` |
| 107 | + |
| 108 | +## Bundle Size Optimization |
| 109 | + |
| 110 | +Enhanced s5.js uses modular exports for optimal bundle sizes: |
| 111 | + |
| 112 | +| Import Path | Size (brotli) | Use Case | |
| 113 | +|-------------|--------------|----------| |
| 114 | +| `@julesl23/s5js` | 61.14 KB | Full functionality | |
| 115 | +| `@julesl23/s5js/core` | 59.58 KB | Basic storage only | |
| 116 | +| `@julesl23/s5js/media` | 9.79 KB | Media processing (standalone) | |
| 117 | +| `@julesl23/s5js/advanced` | 60.60 KB | Core + CID utilities | |
| 118 | + |
| 119 | +**Recommendation:** Import from `@julesl23/s5js/core` and lazy-load media features on demand for optimal initial bundle size. |
| 120 | + |
| 121 | +## Running Demos in Browser |
| 122 | + |
| 123 | +Some demos have HTML versions for browser testing: |
| 124 | + |
| 125 | +```bash |
| 126 | +cd demos/media |
| 127 | +npx http-server . -p 8080 |
| 128 | +# Open http://localhost:8080/demo-splitting.html |
| 129 | +``` |
| 130 | + |
| 131 | +## What's Next? |
| 132 | + |
| 133 | +After exploring these demos: |
| 134 | + |
| 135 | +1. **Read the API Documentation**: [`docs/API.md`](../docs/API.md) - Complete API reference |
| 136 | +2. **Check the Examples**: [`test/integration/`](../test/integration/) - More advanced usage patterns |
| 137 | +3. **Review Performance**: [`docs/BENCHMARKS.md`](../docs/BENCHMARKS.md) - Performance characteristics |
| 138 | +4. **Build Your App**: Use Enhanced s5.js in your own project! |
| 139 | + |
| 140 | +## Troubleshooting |
| 141 | + |
| 142 | +### Module Not Found Error |
| 143 | + |
| 144 | +If you get "Cannot find module '@julesl23/s5js'": |
| 145 | +1. Ensure you've installed the package: `npm install @julesl23/s5js@beta` |
| 146 | +2. Check that you're using Node.js 20 or higher: `node --version` |
| 147 | + |
| 148 | +### WebSocket Connection Issues |
| 149 | + |
| 150 | +If peer connections fail: |
| 151 | +1. Check your internet connection |
| 152 | +2. Verify firewall isn't blocking WebSocket connections |
| 153 | +3. Try alternative peers from the [S5 Protocol Discord](https://discord.gg/s5protocol) |
| 154 | + |
| 155 | +### Browser Compatibility |
| 156 | + |
| 157 | +For browser usage, ensure: |
| 158 | +- ES modules are supported |
| 159 | +- WebAssembly is available (for media processing) |
| 160 | +- IndexedDB is enabled (for local caching) |
| 161 | + |
| 162 | +## Contributing |
| 163 | + |
| 164 | +Found an issue or have an improvement? Open an issue or PR at: |
| 165 | +https://github.com/julesl23/s5.js |
| 166 | + |
| 167 | +## Resources |
| 168 | + |
| 169 | +- **npm Package**: https://www.npmjs.com/package/@julesl23/s5js |
| 170 | +- **GitHub Repository**: https://github.com/julesl23/s5.js |
| 171 | +- **API Documentation**: https://github.com/julesl23/s5.js/blob/main/docs/API.md |
| 172 | +- **S5 Protocol**: https://docs.sfive.net/ |
| 173 | +- **Community Discord**: https://discord.gg/s5protocol |
| 174 | + |
| 175 | +## License |
| 176 | + |
| 177 | +Enhanced s5.js is dual-licensed under MIT OR Apache-2.0. |
0 commit comments