import * as fs from 'fs' ; import { IRandomReader } from '../type' ; /**
 * Provides abstract file access via the IRandomRead interface
 */ export class RandomFileReader implements IRandomReader { private readonly fd : number ; constructor ( filePath , public fileSize ) { this . fd = fs . openSync ( filePath , 'r' ) ; } param buffer { Buffer } param offset { number } param length { number } param position { number } return { Promise < number > } public randomRead ( buffer , offset , length , position ) { return new Promise ( ( resolve , reject ) => { fs . read ( this . fd , buffer , offset , length , position , ( err , bytesRead ) => { if ( err ) { reject ( err ) ; } else { resolve ( bytesRead ) ; } } ) ; } ) ; } public close ( ) { fs . closeSync ( this . fd ) ; } }