stable
blob
Single attachment extraction — one PDF, JPEG, or other blob as native MIME bytes.
@noy-db/as-blob·pnpm add @noy-db/as-blobPulls one blob out of a record'sBlobSetas its native MIME bytes.
What it does
as-blob extracts a single attachment — "give me this PDF, not the
whole vault" — as raw bytes plus its stored MIME type and filename. A
symmetric fromBytes() reader writes bytes back into a slot; because
single-slot writes have no meaningful "merge", its policy alphabet is
'replace' | 'insert-only' (default 'replace') rather than the
three-way policy other readers use, and the plan reports
status: 'added' | 'modified'.
Usage
import { toBytes } from '@noy-db/as-blob'
const { bytes, mime, filename } = await toBytes(vault, {
collection: 'invoices',
id: '01HXX...',
slot: 'raw', // optional, defaults to 'raw'
})
// bytes: Uint8Array — decrypted PDF/PNG/whatever
import { fromBytes } from '@noy-db/as-blob'
const plan = await fromBytes(vault, bytes, { collection: 'invoices', id: '01HXX...' })
// → AsBlobImportPlan { plan: VaultDiff, policy: 'replace', apply() }
await plan.apply()
See also
- as-* family
- zip — records + every attached blob together
- noydb — encrypted-tier alternative