@@ -226,16 +226,16 @@ public bool DecryptFilenames(byte[] encryptionKey)
226226 /// <returns><c>true</c> if serialization was successful; otherwise, <c>false</c>.</returns>
227227 public bool SaveToFile ( string filename )
228228 {
229- using var fs = File . Open ( filename , FileMode . Create ) ;
230- using var bw = new BinaryWriter ( fs ) ;
231- var data = Serialize ( ) ;
232- if ( data != null )
229+ try
233230 {
234- bw . Write ( data ) ;
235- return true ;
231+ using var fs = File . Open ( filename , FileMode . Create ) ;
232+ Serialize ( fs ) ; // Directly pass the FileStream to the Serialize method
233+ return true ; // If serialization completes without throwing an exception, return true
234+ }
235+ catch ( Exception )
236+ {
237+ return false ; // Return false if an error occurs
236238 }
237-
238- return false ;
239239 }
240240
241241 /// <summary>
@@ -390,10 +390,10 @@ public int GetHashCode( byte[] obj )
390390 }
391391
392392 /// <summary>
393- /// Serializes the depot manifest into a byte array .
393+ /// Serializes the depot manifest into the provided output stream .
394394 /// </summary>
395- /// <returns>A byte array containing the serialized depot manifest. Returns <c>null</c> if serialization fails .</returns >
396- public byte [ ] ? Serialize ( )
395+ /// <param name="output">The stream to which the serialized depot manifest will be written .</param >
396+ public void Serialize ( Stream output )
397397 {
398398 DebugLog . Assert ( Files != null , nameof ( DepotManifest ) , "Files was null when attempting to serialize manifest." ) ;
399399
@@ -469,8 +469,7 @@ public int GetHashCode( byte[] obj )
469469 }
470470 }
471471
472- using var ms = new MemoryStream ( ) ;
473- using var bw = new BinaryWriter ( ms ) ;
472+ using var bw = new BinaryWriter ( output , Encoding . Default , true ) ;
474473
475474 // Write Protobuf payload
476475 using ( var ms_payload = new MemoryStream ( ) )
@@ -496,8 +495,6 @@ public int GetHashCode( byte[] obj )
496495
497496 // Write EOF marker
498497 bw . Write ( DepotManifest . PROTOBUF_ENDOFMANIFEST_MAGIC ) ;
499-
500- return ms . ToArray ( ) ;
501498 }
502499 }
503500}
0 commit comments