import { IFile } from './i-file' ; import { IFileDescription } from './i-file-description' ; import { SerializationService } from '../../model/serialization.service' ; interface SerializedFormV1 { version : '1' ; description : string ; name : string ; size : number ; content : string ; } export class GenericFile implements IFile { static deserialize ( serializationService , serializedForm ) { const v1Object = JSON . parse ( serializedForm ) ; return new GenericFile ( serializationService . deserializeIFileDescription ( v1Object . description ) , v1Object . name , v1Object . size , v1Object . content ) ; } constructor ( public description , public name , public size , public content ) { } public serialize ( serializationService ) { const v1Object = { version : '1' , description : this . description . serialize ( serializationService ) , name : this . name , content : this . content , size : this . size } ; return JSON . stringify ( v1Object ) ; } param newContent public copyWithNewContent ( newContent ) { return new GenericFile ( this . description , this . name , newContent . length , newContent ) ; } param saveAs copyForNewDescription ( saveAs ) { return new GenericFile ( saveAs , this . name , this . content . length , this . content ) ; } }