@@ -10,7 +10,7 @@ import { LocaleParams } from "@/types/Params";
1010
1111export default async function IsValidImage ( {
1212 params : { locale } ,
13- } : LocaleParams ) {
13+ } : Readonly < LocaleParams > ) {
1414 setStaticParamsLocale ( locale ) ;
1515
1616 const t = await getScopedI18n ( "DocumentationJsFunctions" ) ;
@@ -45,10 +45,13 @@ export default async function IsValidImage({
4545
4646 < SyntaxHighlighter language = "javascript" style = { a11yDark } >
4747 { `import { isValidImage } from 'multiform-validator';
48- import ImageBuffer from 'image-buffer';
48+ import * as path from 'path';
49+ import * as fs from 'fs';
4950
50- const buffer: Buffer = ImageBuffer;
51- const isValid = isValidImage(buffer);
51+ const filePath = path.join(__dirname, 'image.png');
52+ const fileBuffer = fs.readFileSync(filePath);
53+
54+ const isValid = isValidImage(fileBuffer);
5255
5356console.log(isValid); // true if the image is valid, false otherwise` }
5457 </ SyntaxHighlighter >
@@ -59,37 +62,22 @@ console.log(isValid); // true if the image is valid, false otherwise`}
5962
6063 < SyntaxHighlighter language = "javascript" style = { a11yDark } >
6164 { `import { isValidImage } from 'multiform-validator';
62- import ImageBuffer from 'image-buffer';
65+ import * as path from 'path';
66+ import * as fs from 'fs';
67+
68+ const filePath = path.join(__dirname, 'image.png');
69+ const fileBuffer = fs.readFileSync(filePath);
6370
64- const buffer: Buffer = ImageBuffer;
65- const isValid = isValidImage(buffer, { exclude: ['gif'] });
71+ const isValid = isValidImage(fileBuffer, { exclude: ['gif'] });
6672
6773console.log(isValid); // true if the image is valid, false otherwise` }
6874 </ SyntaxHighlighter >
6975
7076 < h2 className = "mt-6" > { t ( "Example Usage with Nestjs and Multer" ) } </ h2 >
71- < p >
72- { t (
73- "In this example it only allocates 4 bytes for performance reasons, but you can pass the entire file." ,
74- ) }
75- </ p >
7677
7778 < SyntaxHighlighter language = "javascript" style = { a11yDark } >
78- { `const filePath = resolve(process.cwd(), 'public', 'assets', 'images');
79-
80- const fileGetted = resolve(filePath, filename);
81-
82- const buffer = Buffer.alloc(4);
83-
84- const fd = fs.openSync(fileGetted, 'r');
85- fs.readSync(fd, buffer, 0, 4, 0);
86- fs.closeSync(fd);
87-
88- const isValidImageResult = isValidImage(buffer);
89-
90- if (!isValidImageResult) {
91- fs.unlinkSync(fileGetted);
92- throw new BadRequestException('Invalid image');
79+ { `if (!isValidImage(file.buffer)) {
80+ throw new BadRequestException("This is not a valid image");
9381}` }
9482 </ SyntaxHighlighter >
9583 < p className = "mt-6" >
0 commit comments