import { CvsFileStatusCode } from "../../utils/constants" ; import { ByteWriter } from "../../utils/bytewriter" ; import { ReadableSet } from "../../utils/readableset" ; import { Logger } from "../../utils/logger" ; import * as fs from "fs" ; import * as stream from "stream" ; export abstract class CvsResource { protected constructor ( public readonly status , public readonly fileAbsPath , public readonly fileName , public readonly serverFilePath , public readonly prevFileAbsPath ? , public readonly prevServerFilePath ? ) { } public abstract getPrefix ( ) ; public getHeaderForPatch ( ) { const prefix = this . getPrefix ( ) ; const bytePrefix = ByteWriter . writeByte ( prefix ) ; const byteFileName = ByteWriter . writeUTF ( this . serverFilePath ) ; return Buffer . concat ( [ bytePrefix , byteFileName ] ) ; } public async getContentForPatch ( ) { if ( ! this . fileAbsPath ) { const errMsg = "File abs path is undefined. Could not get file content for patching." ; Logger . logError ( errMsg ) ; return Promise . reject ( errMsg ) ; } Logger . logDebug ( `CvsLocalResource#getContentForPatch: file path: ${ this . fileAbsPath }` ) ; const stats = fs . statSync ( this . fileAbsPath ) ; const fileSizeInBytes = stats . size ; Logger . logDebug ( `CvsLocalResource#getContentForPatch: file size in bytes: ${ fileSizeInBytes }` ) ; const readStream = fs . createReadStream ( this . fileAbsPath ) ; return { stream : readStream , length : fileSizeInBytes } ; } }