import fs from 'fs' ; import base64Arraybuffer from 'base64-arraybuffer' ; export default async function ( file ) { try { if ( typeof file === 'string' ) { return base64Arraybuffer . decode ( file ) ; } if ( file && file . path ) { if ( file . path . includes ( '../' ) ) { throw new Error ( 'Not support for this file object' ) ; } const f = fs . readFileSync ( file . path ) ; return f . buffer . slice ( f . byteOffset , f . byteOffset + f . byteLength ) ; } if ( file instanceof Uint8Array ) { return file . buffer . slice ( file . byteOffset , file . byteOffset + file . byteLength ) ; } throw new Error ( 'Not support for this file object' ) ; } catch ( error ) { throw error ; } }