/** * @module item-atom-helper * * Helper functions enforcing canonical space-delimited `ib` atom formulas. * * Formula: `[atom] [fsType] [saferName] [saferNameVersion] [nameHash]` * Example: `b2tfs_item file index_mts v1 a745323851634de188beaebdcb85cbb9` */ export const B2TFS_ITEM_ATOM = 'b2tfs_item'; export const B2TFS_ITEM_SAFER_NAME_VERSION_V1 = 'v1'; export function getB2tFSItemSaferName(rawName: string): string { if (!rawName) { return 'unnamed'; } // Clean to alphanumeric and underscores/dashes/dots const safe = rawName.replace(/[^a-zA-Z0-9_\-\.]/g, '_'); return safe.slice(0, 32); } /** * Returns canonical `ib` metadata string for a B2tFS item. * * @param fsType 'file' or 'folder' * @param name raw file/folder name * @param nameHash SHA-256 hash of name */ export function getB2tFSItemIb(fsType: 'file' | 'folder', name: string, nameHash: string): string { const saferName = getB2tFSItemSaferName(name); return `${B2TFS_ITEM_ATOM} ${fsType} ${saferName} ${B2TFS_ITEM_SAFER_NAME_VERSION_V1} ${nameHash}`; }