@@ -255,24 +255,91 @@ For production deployments, these benchmarks confirm the implementation is ready
255255The library supports multiple import strategies to optimize bundle size:
256256
257257``` javascript
258- // Full bundle (~273KB uncompressed, ~70KB gzipped )
259- import { S5 , MediaProcessor } from " @s5-dev/s5js " ;
258+ // Full bundle (~60KB compressed with brotli )
259+ import { S5 , MediaProcessor } from " s5 " ;
260260
261- // Core only - no media features (~195KB uncompressed, ~51KB gzipped )
261+ // Core only - no media features (~60KB compressed )
262262import { S5 , FS5 } from " s5/core" ;
263263
264- // Media only - for lazy loading (~79KB uncompressed, ~19KB gzipped )
264+ // Media only - for lazy loading (~10KB compressed )
265265import { MediaProcessor } from " s5/media" ;
266266
267+ // Advanced CID API - for power users (~60KB compressed)
268+ import { FS5Advanced , formatCID , parseCID } from " s5/advanced" ;
269+
267270// Dynamic import for code-splitting
268271const { MediaProcessor } = await import (" s5/media" );
269272```
270273
271274Monitor bundle sizes with:
272275``` bash
273- node scripts/analyze-bundle.js
276+ npm run analyze-bundle
277+ ```
278+
279+ ## Advanced CID API
280+
281+ For power users who need direct access to Content Identifiers (CIDs), the Advanced API provides content-addressed storage capabilities without affecting the simplicity of the path-based API.
282+
283+ ### When to Use
284+
285+ ** Use the Advanced API if you:**
286+ - Need to reference content by its cryptographic hash
287+ - Are building content-addressed storage applications
288+ - Require deduplication or content verification
289+ - Work with distributed systems that use CIDs
290+
291+ ** Use the Path-based API if you:**
292+ - Need simple file storage (most use cases)
293+ - Prefer traditional file system operations
294+ - Want paths to be more meaningful than hashes
295+
296+ ### Quick Example
297+
298+ ``` typescript
299+ import { S5 } from " s5" ;
300+ import { FS5Advanced , formatCID , parseCID } from " s5/advanced" ;
301+
302+ // Setup
303+ const s5 = await S5 .create ();
304+ await s5 .recoverIdentityFromSeedPhrase (seedPhrase );
305+ const advanced = new FS5Advanced (s5 .fs );
306+
307+ // Store data and get both path and CID
308+ const result = await advanced .putWithCID (' home/document.txt' , ' Important data' );
309+ console .log (` Path: ${result .path } ` );
310+ console .log (` CID: ${formatCID (result .cid , ' base32' )} ` );
311+
312+ // Share the CID string
313+ const cidString = formatCID (result .cid , ' base58btc' );
314+
315+ // Recipient: retrieve by CID alone
316+ const receivedCID = parseCID (cidString );
317+ const data = await advanced .getByCID (receivedCID );
318+ console .log (data ); // "Important data"
319+
320+ // Find path from CID
321+ const path = await advanced .cidToPath (receivedCID );
322+ console .log (path ); // "home/document.txt"
274323```
275324
325+ ### Available Methods
326+
327+ ** FS5Advanced Class:**
328+ - ` pathToCID(path) ` - Extract CID from file/directory path
329+ - ` cidToPath(cid) ` - Find path for a given CID
330+ - ` getByCID(cid) ` - Retrieve data by CID
331+ - ` putByCID(data) ` - Store data and return CID
332+ - ` putWithCID(path, data) ` - Store and get both path and CID
333+ - ` getMetadataWithCID(path) ` - Get metadata with CID
334+
335+ ** CID Utilities:**
336+ - ` formatCID(cid, encoding?) ` - Format CID as multibase string
337+ - ` parseCID(cidString) ` - Parse CID from string
338+ - ` verifyCID(cid, data, crypto) ` - Verify CID matches data
339+ - ` cidToString(cid) ` - Convert to hex string
340+
341+ See the [ Advanced API Documentation] ( ./docs/API.md#advanced-cid-api ) for complete details.
342+
276343## Encryption
277344
278345Enhanced S5.js includes ** built-in encryption** using XChaCha20-Poly1305, providing both confidentiality and integrity for sensitive data.
0 commit comments