@@ -385,20 +385,20 @@ public sealed class ImageContentBlock : ContentBlock
385385 /// <summary>
386386 /// Creates an <see cref="ImageContentBlock"/> from decoded image bytes.
387387 /// </summary>
388- /// <param name="imageData ">The decoded image bytes.</param>
388+ /// <param name="bytes ">The unencoded image bytes.</param>
389389 /// <param name="mimeType">The MIME type of the image.</param>
390390 /// <returns>A new <see cref="ImageContentBlock"/> instance.</returns>
391391 /// <remarks>
392392 /// This method stores the provided bytes as <see cref="DecodedData"/> and encodes them to base64 UTF-8 bytes for <see cref="Data"/>.
393393 /// </remarks>
394394 /// <exception cref="InvalidOperationException"></exception>
395- public static ImageContentBlock FromBytes ( ReadOnlyMemory < byte > imageData , string mimeType )
395+ public static ImageContentBlock FromBytes ( ReadOnlyMemory < byte > bytes , string mimeType )
396396 {
397- ReadOnlyMemory < byte > data = Base64Helpers . EncodeToBase64Utf8 ( imageData ) ;
397+ ReadOnlyMemory < byte > data = EncodingUtilities . EncodeToBase64Utf8 ( bytes ) ;
398398
399399 return new ( )
400400 {
401- _decodedData = imageData ,
401+ _decodedData = bytes ,
402402 Data = data ,
403403 MimeType = mimeType
404404 } ;
@@ -444,7 +444,7 @@ public ReadOnlyMemory<byte> DecodedData
444444 {
445445 if ( _decodedData is null )
446446 {
447- _decodedData = Base64Helpers . DecodeFromBase64Utf8 ( Data ) ;
447+ _decodedData = EncodingUtilities . DecodeFromBase64Utf8 ( Data ) ;
448448 }
449449
450450 return _decodedData . Value ;
@@ -474,20 +474,20 @@ public sealed class AudioContentBlock : ContentBlock
474474 /// <summary>
475475 /// Creates an <see cref="AudioContentBlock"/> from decoded audio bytes.
476476 /// </summary>
477- /// <param name="audioData ">The decoded audio bytes.</param>
477+ /// <param name="bytes ">The unencoded audio bytes.</param>
478478 /// <param name="mimeType">The MIME type of the audio.</param>
479479 /// <returns>A new <see cref="AudioContentBlock"/> instance.</returns>
480480 /// <remarks>
481481 /// This method stores the provided bytes as <see cref="DecodedData"/> and encodes them to base64 UTF-8 bytes for <see cref="Data"/>.
482482 /// </remarks>
483483 /// <exception cref="InvalidOperationException"></exception>
484- public static AudioContentBlock FromBytes ( ReadOnlyMemory < byte > audioData , string mimeType )
484+ public static AudioContentBlock FromBytes ( ReadOnlyMemory < byte > bytes , string mimeType )
485485 {
486- ReadOnlyMemory < byte > data = Base64Helpers . EncodeToBase64Utf8 ( audioData ) ;
486+ ReadOnlyMemory < byte > data = EncodingUtilities . EncodeToBase64Utf8 ( bytes ) ;
487487
488488 return new ( )
489489 {
490- _decodedData = audioData ,
490+ _decodedData = bytes ,
491491 Data = data ,
492492 MimeType = mimeType
493493 } ;
@@ -533,7 +533,7 @@ public ReadOnlyMemory<byte> DecodedData
533533 {
534534 if ( _decodedData is null )
535535 {
536- _decodedData = Base64Helpers . DecodeFromBase64Utf8 ( Data ) ;
536+ _decodedData = EncodingUtilities . DecodeFromBase64Utf8 ( Data ) ;
537537 }
538538
539539 return _decodedData . Value ;
@@ -757,46 +757,3 @@ private string DebuggerDisplay
757757 }
758758 }
759759}
760-
761- /// <summary>
762- /// Helper methods for base64 encoding and decoding operations.
763- /// </summary>
764- internal static class Base64Helpers
765- {
766- /// <summary>
767- /// Encodes binary data to base64-encoded UTF-8 bytes.
768- /// </summary>
769- internal static ReadOnlyMemory < byte > EncodeToBase64Utf8 ( ReadOnlyMemory < byte > data )
770- {
771- int maxLength = Base64 . GetMaxEncodedToUtf8Length ( data . Length ) ;
772- byte [ ] buffer = new byte [ maxLength ] ;
773- if ( Base64 . EncodeToUtf8 ( data . Span , buffer , out _ , out int bytesWritten ) == OperationStatus . Done )
774- {
775- Debug . Assert ( bytesWritten == buffer . Length , "Base64 encoding should always produce the same length as the max length" ) ;
776- return buffer . AsMemory ( 0 , bytesWritten ) ;
777- }
778- else
779- {
780- throw new InvalidOperationException ( "Failed to encode binary data to base64" ) ;
781- }
782- }
783-
784- /// <summary>
785- /// Decodes base64-encoded UTF-8 bytes to binary data.
786- /// </summary>
787- internal static ReadOnlyMemory < byte > DecodeFromBase64Utf8 ( ReadOnlyMemory < byte > base64Data )
788- {
789- int maxLength = Base64 . GetMaxDecodedFromUtf8Length ( base64Data . Length ) ;
790- byte [ ] buffer = new byte [ maxLength ] ;
791- if ( Base64 . DecodeFromUtf8 ( base64Data . Span , buffer , out _ , out int bytesWritten ) == OperationStatus . Done )
792- {
793- // Base64 decoding may produce fewer bytes than the max length, due to whitespace anywhere in the string or padding.
794- Debug . Assert ( bytesWritten <= buffer . Length , "Base64 decoding should never produce more bytes than the max length" ) ;
795- return buffer . AsMemory ( 0 , bytesWritten ) ;
796- }
797- else
798- {
799- throw new FormatException ( "Invalid base64 data" ) ;
800- }
801- }
802- }
0 commit comments