Skip to content

TypeScript API / laikacms/file-sanitizer / FileSanitizerImpl

Class: FileSanitizerImpl ​

File sanitizer implementation that strips privacy-sensitive metadata from files.

Implements the abstract Sanitizer interface from laikacms/sanitizer.

Example ​

typescript
import { FileSanitizerImpl } from 'laikacms/file-sanitizer';

const sanitizer = new FileSanitizerImpl();

// Check supported types
console.log(sanitizer.getSupportedFileTypes()); // ['png', 'gif', 'webp', 'jpeg']

// Sanitize a file
const result = await sanitizer.sanitize(fileData);

Implements ​

Constructors ​

Constructor ​

ts
new FileSanitizerImpl(): FileSanitizerImpl;

Returns ​

FileSanitizerImpl

Methods ​

canSanitize() ​

ts
canSanitize(data): object;

Check if a file can be sanitized (without actually sanitizing it) Useful for validation before upload

Parameters ​

ParameterType
dataUint8Array

Returns ​

object

canSanitize ​
ts
canSanitize: boolean;
detectedType ​
ts
detectedType: string;
reason? ​
ts
optional reason?: string;

Implementation of ​

Sanitizer.canSanitize


getSupportedFileTypes() ​

ts
getSupportedFileTypes(): readonly string[];

Get a list of supported file types/extensions

Returns ​

readonly string[]

Implementation of ​

Sanitizer.getSupportedFileTypes


sanitize() ​

ts
sanitize(
   data, 
   options?, 
   expectedMimeType?
): Promise<SanitizeResult>;

Sanitize a file, stripping privacy-sensitive metadata

Parameters ​

ParameterTypeDescription
dataUint8ArrayThe file data as a Uint8Array
options?SanitizeOptionsSanitization options
expectedMimeType?stringOptional expected MIME type for validation

Returns ​

Promise<SanitizeResult>

SanitizeResult - the sanitized file data and metadata

Throws ​

if file exceeds maxFileSize

Throws ​

if file type is not supported or MIME type mismatch

Throws ​

if file is corrupted

Implementation of ​

Sanitizer.sanitize

Released under the MIT License.