import { WriteStream } from "fs" ; import { Files } from 'polar-shared/src/util/Files' ; import { Preconditions } from 'polar-shared/src/Preconditions' ; import { Writer } from '../Exporters' ; export class FileWriter implements Writer { private readonly path : string ; private stream ? : WriteStream ; constructor ( path ) { this . path = path ; } public async init ( ) { this . stream = Files . createWriteStream ( this . path ) ; } public async write ( data ) { Preconditions . assertPresent ( this . stream , "no stream" ) ; this . stream ! . write ( data ) ; } public async close ( err ? ) { if ( this . stream ) { this . stream . close ( ) ; } } }