@@ -43,8 +43,7 @@ import { OpmlValidator } from './opmlValidator';
4343import { DotValidator } from './dotValidator' ;
4444import { ApplePanelsValidator } from './applePanelsValidator' ;
4545import { ObfsetValidator } from './obfsetValidator' ;
46- import * as fs from 'fs' ;
47- import * as path from 'path' ;
46+ import { getBasename , getFs , readBinaryFromInput } from '../utils/io' ;
4847
4948export function getValidatorForFormat ( format : string ) : BaseValidator | null {
5049 switch ( format . toLowerCase ( ) ) {
@@ -128,7 +127,7 @@ export async function validateFileOrBuffer(
128127 filenameHint ?: string
129128) : Promise < ValidationResult > {
130129 const isPath = typeof filePathOrBuffer === 'string' ;
131- const name = filenameHint || ( isPath ? path . basename ( filePathOrBuffer ) : 'upload' ) ;
130+ const name = filenameHint || ( isPath ? getBasename ( filePathOrBuffer ) : 'upload' ) ;
132131 const validator = getValidatorForFile ( name ) || getValidatorForFormat ( name ) ;
133132
134133 if ( ! validator ) {
@@ -144,9 +143,9 @@ export async function validateFileOrBuffer(
144143 return ctor . validateFile ( filePathOrBuffer ) ;
145144 }
146145
147- const buf = fs . readFileSync ( filePathOrBuffer ) ;
148- const stats = fs . statSync ( filePathOrBuffer ) ;
149- return validator . validate ( buf , path . basename ( filePathOrBuffer ) , stats . size ) ;
146+ const buf = readBinaryFromInput ( filePathOrBuffer ) ;
147+ const stats = getFs ( ) . statSync ( filePathOrBuffer ) ;
148+ return validator . validate ( buf , getBasename ( filePathOrBuffer ) , stats . size ) ;
150149 }
151150
152151 const buffer = Buffer . isBuffer ( filePathOrBuffer )
0 commit comments