Skip to content

Commit 64628e8

Browse files
author
Developer
committed
docs: complete Phase 6.5.6 - Advanced CID API documentation
Comprehensive documentation for the Advanced CID API: - docs/API.md: Add 500+ line Advanced CID API section with complete examples - FS5Advanced class (pathToCID, cidToPath, getByCID, putByCID, putWithCID, getMetadataWithCID) - CID utilities (formatCID, parseCID, verifyCID, cidToString) - 10+ code examples showing real-world usage - When to use guidance (advanced vs path-based API) - Bundle size and type definitions reference - README.md: Add Advanced CID API section with quick start - Import examples for s5/advanced export - Complete workflow example - Available methods list - Updated bundle sizes (Advanced: 59.53 KB) - docs/IMPLEMENTATION.md: Mark Phase 6.5 complete - All 6 sub-phases complete (6.5.1 through 6.5.6) - 74/74 tests passing (38 CID utils + 36 FS5Advanced) - Achievement: Clean architectural separation maintained Phase 6.5 now 100% complete with comprehensive documentation.
1 parent f12538a commit 64628e8

File tree

3 files changed

+592
-13
lines changed

3 files changed

+592
-13
lines changed

README.md

Lines changed: 72 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -255,24 +255,91 @@ For production deployments, these benchmarks confirm the implementation is ready
255255
The 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)
262262
import { S5, FS5 } from "s5/core";
263263

264-
// Media only - for lazy loading (~79KB uncompressed, ~19KB gzipped)
264+
// Media only - for lazy loading (~10KB compressed)
265265
import { 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
268271
const { MediaProcessor } = await import("s5/media");
269272
```
270273

271274
Monitor 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

278345
Enhanced S5.js includes **built-in encryption** using XChaCha20-Poly1305, providing both confidentiality and integrity for sensitive data.

0 commit comments

Comments
 (0)