Binary and base64 validators
Extend zod
with a custom module, like src/zod.ts
in your project:
export * from 'zod'
export * from 'zod-file'
Use it in your schema:
import * as z from './zod'
const User = z.object({
avatar: z.base64(),
})
const parsedUser = User.parse({
// Pass a buffer or a base64 string.
avatar: fs.readFileSync('avatar.png'),
})
// Receive a base64 string.
const base64Avatar = parsedUser.avatar
// Invalid base64 strings will throw.
User.parse({
avatar: 'not base64',
})