import { CacheEntry , DataCallback } from './CacheEntry' ; import fs from 'fs' ; import ErrnoException = NodeJS . ErrnoException ; /**
 * Cache entry which is just buffered in memory.
 */ export class DiskCacheEntry extends CacheEntry { /**
     * The data we should serve.
     */ public path : string ; constructor ( options ) { super ( options ) ; this . path = options . path ; if ( this . path === undefined ) { throw new Error ( "No path" ) ; } } public async handleData ( callback ) { return new Promise < boolean > ( ( resolve , reject ) => { fs . readFile ( this . path , ( err , data ) => { if ( err ) { reject ( err ) ; } callback ( data ) ; resolve ( false ) ; } ) ; } ) ; } public async toBuffer ( ) { return new Promise < Buffer > ( ( resolve , reject ) => { fs . readFile ( this . path , ( err , data ) => { if ( err ) { reject ( err ) ; } resolve ( data ) ; } ) ; } ) ; } public async toStream ( ) { return fs . createReadStream ( this . path ) ; } }