@@ -226,16 +226,16 @@ public bool DecryptFilenames(byte[] encryptionKey)
226
226
/// <returns><c>true</c> if serialization was successful; otherwise, <c>false</c>.</returns>
227
227
public bool SaveToFile ( string filename )
228
228
{
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
233
230
{
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
236
238
}
237
-
238
- return false ;
239
239
}
240
240
241
241
/// <summary>
@@ -390,10 +390,10 @@ public int GetHashCode( byte[] obj )
390
390
}
391
391
392
392
/// <summary>
393
- /// Serializes the depot manifest into a byte array .
393
+ /// Serializes the depot manifest into the provided output stream .
394
394
/// </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 )
397
397
{
398
398
DebugLog . Assert ( Files != null , nameof ( DepotManifest ) , "Files was null when attempting to serialize manifest." ) ;
399
399
@@ -469,8 +469,7 @@ public int GetHashCode( byte[] obj )
469
469
}
470
470
}
471
471
472
- using var ms = new MemoryStream ( ) ;
473
- using var bw = new BinaryWriter ( ms ) ;
472
+ using var bw = new BinaryWriter ( output , Encoding . Default , true ) ;
474
473
475
474
// Write Protobuf payload
476
475
using ( var ms_payload = new MemoryStream ( ) )
@@ -496,8 +495,6 @@ public int GetHashCode( byte[] obj )
496
495
497
496
// Write EOF marker
498
497
bw . Write ( DepotManifest . PROTOBUF_ENDOFMANIFEST_MAGIC ) ;
499
-
500
- return ms . ToArray ( ) ;
501
498
}
502
499
}
503
500
}
0 commit comments