import { CvsResource } from "../../bll/entities/cvsresources/cvsresource" ; import { Utils } from "../../bll/utils/utils" ; import * as stream from "stream" ; import { Logger } from "../../bll/utils/logger" ; import { CpProxy } from "../../bll/moduleproxies/cp-proxy" ; export class GetStagedFileContentLength { constructor ( private readonly workspaceRootPath , private readonly gitPath , private readonly cvsResource , private readonly cpProxy ) { } public execute ( ) { const relativePath = Utils . getNormalizedRelativePath ( this . cvsResource , this . workspaceRootPath ) ; const options = this . getCommandOptions ( relativePath ) ; const showFileStream = this . cpProxy . spawn ( `${ this . gitPath }` , options ) . stdout ; let streamLength = 0 ; return new Promise < number > ( ( resolve , reject ) => { showFileStream . on ( "end" , ( ) => { Logger . logDebug ( `GitSupportProvider#getStagedFileContentLength: stream for counting ` + `bytes of ${ this . cvsResource . fileAbsPath } has ended. Total size is ${ streamLength }` ) ; resolve ( streamLength ) ; } ) ; showFileStream . on ( "close" , ( ) => { Logger . logError ( `GitSupportProvider#getStagedFileContentLength: Stream was closed before it ended` ) ; reject ( "GitProvider#getStagedFileContentLength: Stream was closed before it ended" ) ; } ) ; showFileStream . on ( "error" , ( err ) => { Logger . logError ( `GitSupportProvider#getStagedFileContentLength: stream for counting ` + `bytes of ${ this . cvsResource . fileAbsPath } has ended exited with error
                     ${ Utils . formatErrorMessage ( err ) }` ) ; reject ( err ) ; } ) ; showFileStream . on ( "data" , ( chunk ) => { streamLength += chunk . length ; } ) ; } ) ; } private getCommandOptions ( relativePath ) { return [ `-C` , `${ this . workspaceRootPath }` , `show` , `:${ relativePath }` ] ; } }