fix(transport): serialise the export content once and pack those bytes (review 2026-10-21 04/P8a)
This commit is contained in:
@@ -57,6 +57,28 @@ public sealed class BundleSerializer
|
||||
BundleSecretEncryptor? encryptor)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(content);
|
||||
return PackContentBytes(SerializeContentBytes(content), manifest, passphrase, encryptor);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Packs already-serialised content (the output of <see cref="SerializeContentBytes"/>)
|
||||
/// and the manifest into a ZIP stream, optionally encrypting the content. Lets a caller
|
||||
/// that has already serialised the DTO — e.g. to hash it for the manifest — pack those
|
||||
/// same bytes instead of serialising the whole graph a second time (review 2026-10-21
|
||||
/// 04/P8a).
|
||||
/// </summary>
|
||||
/// <param name="contentBytes">The serialised bundle content JSON.</param>
|
||||
/// <param name="manifest">The bundle manifest describing the content and encryption metadata.</param>
|
||||
/// <param name="passphrase">Passphrase used for encryption; null produces a plaintext bundle.</param>
|
||||
/// <param name="encryptor">Encryptor required when <paramref name="passphrase"/> is supplied.</param>
|
||||
/// <returns>A seeked-to-start <see cref="MemoryStream"/> containing the bundle ZIP archive.</returns>
|
||||
public Stream PackContentBytes(
|
||||
byte[] contentBytes,
|
||||
BundleManifest manifest,
|
||||
string? passphrase,
|
||||
BundleSecretEncryptor? encryptor)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(contentBytes);
|
||||
ArgumentNullException.ThrowIfNull(manifest);
|
||||
|
||||
if (passphrase is not null && encryptor is null)
|
||||
@@ -68,7 +90,6 @@ public sealed class BundleSerializer
|
||||
throw new ArgumentException("Manifest must carry EncryptionMetadata when packing an encrypted bundle.", nameof(manifest));
|
||||
}
|
||||
|
||||
var contentBytes = SerializeContentBytes(content);
|
||||
byte[] payload;
|
||||
string payloadEntryName;
|
||||
BundleManifest finalManifest;
|
||||
|
||||
Reference in New Issue
Block a user