SCHEMA
Validation Methods
.buffer

Schema - Buffer

The .buffer method is used to validate whether a given value is of type Buffer. It ensures that the input is an instance of the Buffer class, which is typically used to handle raw binary data, such as when working with files, streams, or binary communication.

This method is essential for enforcing strict type validation where only Buffer values are acceptable, making it useful for scenarios like validating binary data, file uploads, or raw byte streams.


Example

Below is an example of how to use .buffer to validate whether a value is a valid Buffer:

import { schema } from "vkrun"
 
const schemaValidation = schema().buffer()
 
const validateA = schemaValidation.validate(Buffer.from("test"))  // Valid Buffer
const validateB = schemaValidation.validate("test")               // Invalid, string is not a Buffer
 
console.log(validateA) // true
console.log(validateB) // false
Copyright © 2024 MIT by Mario Elvio